/* ==========================================================
   Tema: "Pregão ao entardecer" — tinta quase preta, dourado
   queimado e verde-água. Números em mono, títulos em serifa.
   ========================================================== */
:root {
  --bg: #0a0c10;
  --bg-2: #0e1117;
  --surface: rgba(20, 24, 32, 0.72);
  --surface-solid: #141820;
  --surface-2: #1b2029;
  --line: rgba(255, 255, 255, 0.07);
  --line-2: rgba(255, 255, 255, 0.13);
  --text: #ece8dd;
  --muted: #8a909c;
  --gold: #e8b65a;
  --gold-soft: rgba(232, 182, 90, 0.14);
  --up: #3ddc97;
  --up-soft: rgba(61, 220, 151, 0.13);
  --down: #ff6b6b;
  --down-soft: rgba(255, 107, 107, 0.13);
  --shadow: 0 20px 50px -20px rgba(0, 0, 0, 0.6);
  --radius: 18px;
  --serif: "Fraunces", Georgia, serif;
  --sans: "Manrope", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

[data-theme="light"] {
  --bg: #f5f1e8;
  --bg-2: #efe9db;
  --surface: rgba(255, 253, 248, 0.8);
  --surface-solid: #fffdf8;
  --surface-2: #f2ede1;
  --line: rgba(40, 30, 10, 0.08);
  --line-2: rgba(40, 30, 10, 0.16);
  --text: #1c1a16;
  --muted: #6e6a60;
  --gold: #a8741a;
  --gold-soft: rgba(168, 116, 26, 0.12);
  --up: #14844f;
  --up-soft: rgba(20, 132, 79, 0.1);
  --down: #c2373a;
  --down-soft: rgba(194, 55, 58, 0.09);
  --shadow: 0 18px 40px -22px rgba(60, 40, 10, 0.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }

body {
  background:
    radial-gradient(900px 480px at 92% -8%, var(--gold-soft), transparent 70%),
    radial-gradient(700px 420px at -5% 30%, rgba(61, 220, 151, 0.05), transparent 70%),
    var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.4s ease, color 0.4s ease;
}

button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

.up { color: var(--up); }
.down { color: var(--down); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mt { margin-top: 26px; }

/* ---------- Fita de cotações ---------- */
.tape {
  overflow: hidden;
  border-bottom: 1px solid var(--line);
  background: var(--surface-solid);
  mask-image: linear-gradient(90deg, transparent, #000 6%, #000 94%, transparent);
}
.tape-track {
  display: flex;
  width: max-content;
  gap: 42px;
  padding: 10px 0;
  animation: scroll 60s linear infinite;
}
.tape:hover .tape-track { animation-play-state: paused; }
.tape-item {
  display: inline-flex;
  gap: 10px;
  font-family: var(--mono);
  font-size: 13px;
  white-space: nowrap;
}
.tape-item b { font-weight: 700; }
@keyframes scroll { to { transform: translateX(-50%); } }

/* ---------- Layout base ---------- */
.shell {
  max-width: 1240px;
  margin: 0 auto;
  padding: 24px 20px 56px;
}

/* ---------- Navegação ---------- */
.nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 26px;
}
.brand { display: flex; align-items: center; gap: 14px; }
.logo {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border-radius: 13px;
  background: linear-gradient(135deg, var(--gold), #b97b2a);
  color: #1a1306;
  box-shadow: 0 10px 24px -10px var(--gold);
}
.logo svg { width: 26px; height: 26px; }

h1 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 500;
  font-size: 26px;
  letter-spacing: -0.02em;
}
h1 em { color: var(--gold); font-weight: 300; font-style: italic; }
h2 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 500;
  font-size: 21px;
  letter-spacing: -0.01em;
}
.sub { margin: 3px 0 0; color: var(--muted); font-size: 13px; }

.nav-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.time {
  font-family: var(--mono);
  font-size: 15px;
  color: var(--muted);
  min-width: 78px;
}

.pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--line-2);
  font-size: 12px;
  color: var(--muted);
  background: var(--surface);
}
.pill i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.pill.open { color: var(--up); border-color: rgba(61, 220, 151, 0.35); }
.pill.open i { background: var(--up); animation: beat 2s infinite; }
.pill.error { color: var(--down); border-color: rgba(255, 107, 107, 0.35); }
.pill.error i { background: var(--down); }
@keyframes beat {
  0%, 100% { box-shadow: 0 0 0 0 rgba(61, 220, 151, 0.5); }
  60% { box-shadow: 0 0 0 7px rgba(61, 220, 151, 0); }
}

/* ---------- Botões ---------- */
.btn, .icon-btn {
  border-radius: 12px;
  border: 1px solid var(--line-2);
  background: var(--surface);
  padding: 9px 14px;
  font-weight: 600;
  font-size: 13px;
  transition: transform 0.15s ease, background 0.2s, border-color 0.2s, color 0.2s;
}
.btn:hover, .icon-btn:hover { border-color: var(--gold); transform: translateY(-1px); }
.btn.primary {
  background: linear-gradient(135deg, var(--gold), #c98d35);
  color: #1a1306;
  border-color: transparent;
}
.btn.ghost { background: transparent; }
.btn.danger:hover { color: var(--down); border-color: var(--down); }
.icon-btn { width: 40px; height: 40px; padding: 0; display: grid; place-items: center; }
.icon-btn svg { width: 18px; height: 18px; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }

.segmented {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--line-2);
  border-radius: 12px;
  padding: 3px;
  gap: 2px;
}
.segmented button {
  background: none;
  border: 0;
  border-radius: 9px;
  padding: 7px 13px;
  color: var(--muted);
  font-weight: 600;
  font-size: 13px;
  transition: background 0.2s, color 0.2s;
}
.segmented button:hover { color: var(--text); }
.segmented button.active { background: var(--surface-2); color: var(--gold); box-shadow: inset 0 0 0 1px var(--line-2); }
.small-seg button { padding: 6px 10px; font-size: 12px; }

/* ---------- Hero ---------- */
.hero {
  display: grid;
  grid-template-columns: 1.7fr 1fr 1fr 1fr;
  gap: 14px;
  margin-bottom: 26px;
}
.hero-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 22px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: hidden;
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
}
.hero-card.main { min-height: 170px; }
.eyebrow {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}
.hero-value {
  font-family: var(--mono);
  font-size: clamp(30px, 4vw, 44px);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
  transition: color 0.3s;
}
.hero-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.delta {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 13px;
  padding: 4px 9px;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--muted);
}
.delta.up { background: var(--up-soft); color: var(--up); }
.delta.down { background: var(--down-soft); color: var(--down); }
.stat { font-family: var(--mono); font-size: 24px; font-weight: 700; }
.hero-spark {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  width: 100%; height: 70px;
  opacity: 0.9;
  pointer-events: none;
}

/* ---------- Seções ---------- */
.section { margin-bottom: 26px; }
.section-head, .panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
}

.view { min-height: 120px; }

/* Cards de ativos */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}
.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 18px 12px;
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: transform 0.25s ease, border-color 0.25s ease;
  animation: rise 0.5s ease both;
  animation-delay: calc(var(--i, 0) * 50ms);
}
.card:hover { transform: translateY(-3px); border-color: var(--accent, var(--gold)); }
.card::after {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
  background: var(--accent);
}
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }

.card-top { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.ticker { font-family: var(--mono); font-weight: 700; font-size: 17px; }
.card-name {
  color: var(--muted); font-size: 12px; margin-top: 2px;
  max-width: 180px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.badge {
  font-family: var(--mono); font-size: 12px; font-weight: 700;
  padding: 4px 8px; border-radius: 8px; white-space: nowrap;
}
.badge.up { background: var(--up-soft); color: var(--up); }
.badge.down { background: var(--down-soft); color: var(--down); }
.badge.flat { background: var(--surface-2); color: var(--muted); }

.price {
  font-family: var(--mono);
  font-size: 27px;
  font-weight: 500;
  margin: 14px 0 2px;
  border-radius: 6px;
  transition: background-color 0.6s ease;
}
.price.flash-up { background: var(--up-soft); }
.price.flash-down { background: var(--down-soft); }

.card-meta {
  display: flex; justify-content: space-between; gap: 8px;
  font-size: 12px; color: var(--muted); font-family: var(--mono);
}
.card-foot { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); font-family: var(--mono); margin-top: 6px; }
.spark { width: 100%; height: 48px; margin-top: 10px; display: block; }
.pos-tag {
  display: inline-block; margin-top: 8px; font-size: 11px; font-weight: 700;
  color: var(--gold); background: var(--gold-soft); padding: 3px 8px; border-radius: 6px;
}

/* Tabela */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow-x: auto;
  box-shadow: var(--shadow);
}
table { width: 100%; border-collapse: collapse; min-width: 640px; }
th, td { padding: 14px 16px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr { transition: background 0.2s; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
td .t { font-family: var(--mono); font-weight: 700; }
td .n { display: block; font-size: 12px; color: var(--muted); max-width: 240px; overflow: hidden; text-overflow: ellipsis; }

/* Mapa de calor */
.heat {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}
.tile {
  border-radius: 16px;
  padding: 18px;
  min-height: 130px;
  display: flex; flex-direction: column; justify-content: space-between;
  border: 1px solid var(--line);
  background: var(--tile-bg);
  transition: transform 0.2s;
}
.tile:hover { transform: scale(1.02); }
.tile .t { font-family: var(--mono); font-weight: 700; font-size: 16px; }
.tile .p { font-family: var(--mono); font-size: 13px; opacity: 0.9; }
.tile .c { font-family: var(--mono); font-size: 26px; font-weight: 700; }

/* ---------- Grid de painéis ---------- */
.grid-2 {
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: 14px;
  align-items: start;
}
.stack { display: flex; flex-direction: column; gap: 14px; }
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}
.panel h2 { margin-bottom: 2px; }
.panel-head { margin-bottom: 8px; }

.legend { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 5px 11px; border-radius: 999px;
  border: 1px solid var(--line-2); background: var(--surface-2);
  font-family: var(--mono); font-size: 12px;
  transition: opacity 0.2s;
}
.chip .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--c); }
.chip.off { opacity: 0.35; }

.chart-wrap { position: relative; }
#chart { width: 100%; height: auto; display: block; }
#chart text { fill: var(--muted); font-family: var(--mono); font-size: 13px; }
#chart .grid { stroke: var(--line); }
#chart .zero { stroke: var(--line-2); stroke-dasharray: 4 5; }
#chart .series { fill: none; stroke-width: 2.4; stroke-linejoin: round; stroke-linecap: round; }
#chart .cursor { stroke: var(--line-2); }
#chart .empty-msg { font-family: var(--sans); font-size: 15px; }

.tooltip {
  position: absolute; top: 12px;
  min-width: 170px;
  transform: translateX(-50%);
  pointer-events: none;
  background: var(--surface-solid);
  border: 1px solid var(--line-2);
  border-radius: 12px;
  padding: 10px 12px;
  box-shadow: var(--shadow);
  font-size: 12px;
}
.tooltip .tt-time { color: var(--muted); font-family: var(--mono); margin-bottom: 6px; }
.tooltip .tt-row { display: flex; justify-content: space-between; gap: 14px; font-family: var(--mono); }

/* Alocação */
.alloc { display: flex; align-items: center; gap: 18px; margin-top: 14px; flex-wrap: wrap; }
#donut { width: 150px; height: 150px; flex-shrink: 0; }
#donut circle.seg { fill: none; stroke-width: 22; transition: stroke-dasharray 0.6s ease; }
#donut text { fill: var(--text); font-family: var(--mono); }
.alloc-list { list-style: none; margin: 0; padding: 0; flex: 1; min-width: 150px; display: grid; gap: 8px; }
.alloc-list li { display: flex; align-items: center; gap: 8px; font-family: var(--mono); font-size: 12px; }
.alloc-list .dot { width: 9px; height: 9px; border-radius: 3px; background: var(--c); flex-shrink: 0; }
.alloc-list .w { margin-left: auto; color: var(--muted); }
.empty { color: var(--muted); font-size: 13px; padding: 10px 0; }

/* Alertas */
.alert-list { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 8px; }
.alert-list li {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 12px; background: var(--surface-2);
  font-size: 13px;
}
.alert-list .tag { font-family: var(--mono); font-size: 11px; font-weight: 700; padding: 3px 7px; border-radius: 6px; }
.alert-list .tag.on { background: var(--gold-soft); color: var(--gold); }
.alert-list .tag.hit { background: var(--up-soft); color: var(--up); }
.alert-list .rm { background: none; border: 0; color: var(--muted); font-size: 16px; padding: 2px 6px; border-radius: 6px; }
.alert-list .rm:hover { color: var(--down); }

/* ---------- Rodapé ---------- */
.foot {
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px;
  margin-top: 28px; padding-top: 18px; border-top: 1px solid var(--line);
  color: var(--muted); font-size: 12px;
}

/* ---------- Diálogo ---------- */
.dialog {
  width: min(680px, calc(100vw - 24px));
  border: 1px solid var(--line-2);
  border-radius: 22px;
  background: var(--surface-solid);
  color: var(--text);
  padding: 26px;
  box-shadow: 0 40px 80px -20px rgba(0, 0, 0, 0.7);
}
.dialog::backdrop { background: rgba(4, 6, 10, 0.6); backdrop-filter: blur(4px); }
.dialog[open] { animation: pop 0.25s ease; }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
.dialog-close { position: absolute; right: 16px; top: 16px; }
.dialog-close .icon-btn { width: 34px; height: 34px; font-size: 14px; }

.pos-table { display: grid; gap: 8px; margin-top: 14px; max-height: 40vh; overflow: auto; padding-right: 4px; }
.pos-row {
  display: grid; grid-template-columns: 1.1fr 1fr 1fr; gap: 10px; align-items: center;
  padding: 10px 12px; border-radius: 12px; background: var(--surface-2);
}
.pos-row .t { font-family: var(--mono); font-weight: 700; }
.pos-row .n { font-size: 11px; color: var(--muted); display: block; }
input, select {
  width: 100%;
  padding: 9px 11px;
  border-radius: 10px;
  border: 1px solid var(--line-2);
  background: var(--bg-2);
  font-family: var(--mono);
  font-size: 13px;
}
input:focus, select:focus { outline: 2px solid var(--gold); outline-offset: 1px; }
.alert-form { display: grid; grid-template-columns: 1fr 1.2fr 1fr auto; gap: 8px; margin-top: 12px; }
.dialog-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 22px; }

/* ---------- Notificações ---------- */
.toasts { position: fixed; right: 18px; bottom: 18px; display: grid; gap: 10px; z-index: 50; }
.toast {
  min-width: 240px; max-width: 340px;
  padding: 12px 14px; border-radius: 14px;
  background: var(--surface-solid); border: 1px solid var(--line-2);
  box-shadow: var(--shadow); font-size: 13px;
  border-left: 4px solid var(--gold);
  animation: pop 0.3s ease;
}
.toast.up { border-left-color: var(--up); }
.toast.down { border-left-color: var(--down); }
.toast.leave { opacity: 0; transition: opacity 0.4s; }

/* ---------- Responsivo ---------- */
@media (max-width: 1000px) {
  .hero { grid-template-columns: 1fr 1fr; }
  .hero-card.main { grid-column: 1 / -1; }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 620px) {
  h1 { font-size: 21px; }
  .time { display: none; }
  .alert-form { grid-template-columns: 1fr 1fr; }
  .alert-form button { grid-column: 1 / -1; }
  .pos-row { grid-template-columns: 1fr; }
  .segmented button { padding: 6px 9px; font-size: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
