/* ==========================================================================
   Macro Pulse — "Cédula"
   Base compartilhada: tokens, tipografia e componentes do mundo papel-moeda.
   Ver DESIGN.md. Cor de classe = categoria do ativo; alta/baixa têm par próprio.
   ========================================================================== */

:root {
  color-scheme: light;

  /* Papel e tinta */
  --ground: #EEF1EC;
  --sheet: #F8FAF6;
  --sheet-2: #F2F5F0;
  --ink: #13202A;
  --ink-2: #45535F;
  --ink-3: #5C6973;
  --rule: #C9D1C8;
  --rule-2: #DCE2DA;
  --micro: #9AA79E;

  /* Denominações (classe de ativo) */
  --c-bolsa: #1F5F8B;
  --c-cambio: #A9521C;
  --c-stable: #6E4A92;
  --c-juros: #7A6248;
  --c-commod: #855F00;
  --c-cripto: #3F6A78;

  /* Direção */
  --up: #1C7A4A;
  --down: #B3261E;
  --flat: #5C6973;

  /* Compatibilidade com nomes antigos usados no JS */
  --positive: var(--up);
  --negative: var(--down);
  --neutral: var(--flat);
  --text-muted: var(--ink-3);

  --font: "Archivo", "Helvetica Neue", Arial, system-ui, sans-serif;
  --radius: 2px;
  --shadow: 0 1px 0 var(--rule), 0 10px 22px -18px rgba(19, 32, 42, 0.35);
  --focus: 0 0 0 2px var(--sheet), 0 0 0 4px var(--ink);
  --wrap: 1320px;
  --gutter: 16px;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --ground: #0D1317;
  --sheet: #141C21;
  --sheet-2: #182227;
  --ink: #E4E9E3;
  --ink-2: #AEB9BD;
  --ink-3: #8D9AA2;
  --rule: #2C373D;
  --rule-2: #222C32;
  --micro: #3D4A50;

  --c-bolsa: #74B4E2;
  --c-cambio: #E8955C;
  --c-stable: #B99BDC;
  --c-juros: #CBB291;
  --c-commod: #E3B94A;
  --c-cripto: #8CBBC8;

  --up: #5FCB91;
  --down: #F27F72;
  --flat: #8D9AA2;

  --shadow: 0 1px 0 #0A0F12, 0 12px 26px -20px rgba(0, 0, 0, 0.9);
  --focus: 0 0 0 2px var(--sheet), 0 0 0 4px var(--ink);
}

@media (min-width: 900px) {
  :root { --gutter: 24px; }
}

/* ---------- Base ---------- */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-padding-top: 72px; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  font-variation-settings: "wdth" 100;
  font-feature-settings: "tnum" 1, "lnum" 1;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

img, svg, canvas { display: block; max-width: 100%; }

a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { color: var(--c-bolsa); }

button, input, select, textarea { font: inherit; color: inherit; }

:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--radius); }

[hidden] { display: none !important; }

.mp-sr {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.mp-wrap { width: min(var(--wrap), 100% - 2 * var(--gutter)); margin-inline: auto; }

/* ---------- Tipografia ---------- */

.mp-h1, .mp-h2, .mp-h3 { margin: 0; color: var(--ink); text-wrap: balance; }

.mp-h1 {
  font-size: clamp(2rem, 1.2rem + 3.4vw, 4.1rem);
  line-height: 0.98;
  font-weight: 700;
  font-variation-settings: "wdth" 82;
  letter-spacing: -0.025em;
}

.mp-h2 {
  font-size: clamp(1.35rem, 1.1rem + 0.9vw, 1.85rem);
  line-height: 1.08;
  font-weight: 700;
  font-variation-settings: "wdth" 88;
  letter-spacing: -0.015em;
}

.mp-h3 {
  font-size: 1.05rem;
  line-height: 1.25;
  font-weight: 650;
  font-variation-settings: "wdth" 94;
}

.mp-lede { margin: 0; color: var(--ink-2); font-size: 1.02rem; max-width: 62ch; text-wrap: pretty; }

.mp-label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ink-3);
  letter-spacing: 0.01em;
}

/* Numeral de denominação: grotesca expandida pesada, tabular */
.mp-denom {
  font-weight: 800;
  font-variation-settings: "wdth" 122;
  font-size: clamp(2.4rem, 1.6rem + 3vw, 4.4rem);
  line-height: 0.92;
  letter-spacing: -0.035em;
  font-feature-settings: "tnum" 1, "lnum" 1;
  white-space: nowrap;
}
.mp-denom--md { font-size: clamp(1.6rem, 1.3rem + 1vw, 2.15rem); letter-spacing: -0.025em; }
.mp-denom--sm { font-size: 1.3rem; letter-spacing: -0.02em; }

.mp-num { font-feature-settings: "tnum" 1, "lnum" 1; white-space: nowrap; }

/* Série do pregão e microimpressão: os dois únicos lugares em versalete */
.mp-serial {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-variation-settings: "wdth" 112;
  color: var(--ink-2);
  white-space: nowrap;
}
.mp-serial b { color: var(--down); font-weight: 700; }

.mp-micro {
  height: 9px;
  overflow: hidden;
  white-space: nowrap;
  font-size: 6px;
  line-height: 9px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  font-weight: 600;
  color: var(--micro);
  user-select: none;
  border-block: 1px solid var(--rule-2);
  font-variation-settings: "wdth" 70;
}

/* ---------- Tom de variação ---------- */

[data-tone="positive"] { color: var(--up); }
[data-tone="negative"] { color: var(--down); }
[data-tone="neutral"] { color: var(--flat); }

.mp-delta {
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
  font-weight: 700;
  font-variation-settings: "wdth" 104;
  white-space: nowrap;
}
.mp-delta[data-tone="positive"]::before { content: "▲"; font-size: 0.7em; }
.mp-delta[data-tone="negative"]::before { content: "▼"; font-size: 0.7em; }

/* Selo de variação (carimbo) */
.mp-stamp {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  padding: 0.28em 0.6em 0.24em;
  border: 1.5px solid currentColor;
  border-radius: var(--radius);
  font-weight: 800;
  font-variation-settings: "wdth" 110;
  font-size: 0.95rem;
  line-height: 1.1;
  white-space: nowrap;
}
.mp-stamp[data-tone="positive"]::before { content: "▲"; font-size: 0.7em; }
.mp-stamp[data-tone="negative"]::before { content: "▼"; font-size: 0.7em; }

/* ---------- Classes de ativo (campo de denominação) ---------- */

[data-asset="bolsa"]  { --cls: var(--c-bolsa); }
[data-asset="cambio"] { --cls: var(--c-cambio); }
[data-asset="stable"] { --cls: var(--c-stable); }
[data-asset="juros"]  { --cls: var(--c-juros); }
[data-asset="commod"] { --cls: var(--c-commod); }
[data-asset="cripto"] { --cls: var(--c-cripto); }

:where(.mp-field) { --cls: var(--ink); }
.mp-field {
  position: relative;
  background: color-mix(in oklab, var(--cls) 9%, var(--sheet));
  border: 1px solid color-mix(in oklab, var(--cls) 30%, var(--rule));
  border-radius: var(--radius);
}
:root[data-theme="dark"] .mp-field { background: color-mix(in oklab, var(--cls) 10%, var(--sheet)); }

.mp-field__tag {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--cls);
  font-variation-settings: "wdth" 100;
}
.mp-field__tag::before {
  content: "";
  width: 10px; height: 10px;
  background: var(--cls);
  border-radius: 1px;
  flex: none;
}

/* ---------- Superfícies ---------- */

.mp-sheet {
  background: var(--sheet);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* Painel-documento: fio duplo */
.mp-doc {
  position: relative;
  background: var(--sheet);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.mp-doc::after {
  content: "";
  position: absolute;
  inset: 5px;
  border: 1px solid var(--rule-2);
  border-radius: 1px;
  pointer-events: none;
}

/* ---------- Controles ---------- */

.mp-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid var(--ink);
  border-radius: var(--radius);
  background: var(--ink);
  color: var(--sheet);
  font-weight: 650;
  font-size: 0.95rem;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 160ms var(--ease), color 160ms var(--ease), transform 160ms var(--ease);
}
.mp-btn:hover { color: var(--sheet); background: color-mix(in oklab, var(--ink) 86%, var(--c-bolsa)); }
.mp-btn:active { transform: translateY(1px); }
.mp-btn svg { width: 16px; height: 16px; flex: none; }

.mp-btn--ghost { background: transparent; color: var(--ink); border-color: var(--rule); }
.mp-btn--ghost:hover { color: var(--ink); background: var(--sheet-2); border-color: var(--ink-3); }

.mp-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--sheet);
  color: var(--ink-2);
  font-size: 0.86rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: border-color 140ms var(--ease), color 140ms var(--ease), background-color 140ms var(--ease);
}
.mp-chip:hover { color: var(--ink); border-color: var(--ink-3); }
.mp-chip.is-active,
.mp-chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--sheet); }

.mp-iconbtn {
  display: inline-grid;
  place-items: center;
  width: 40px; height: 40px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
  text-decoration: none;
  transition: background-color 140ms var(--ease), color 140ms var(--ease);
}
.mp-iconbtn:hover { background: var(--sheet-2); color: var(--ink); border-color: var(--rule); }
.mp-iconbtn svg { width: 18px; height: 18px; }

.mp-input {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--sheet);
  color: var(--ink);
}
.mp-input::placeholder { color: var(--ink-3); }

/* ---------- Cabeçalho (masthead) ---------- */

.mp-masthead {
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in oklab, var(--ground) 94%, transparent);
  border-bottom: 1px solid var(--rule);
}
@supports (backdrop-filter: blur(1px)) {
  .mp-masthead { background: color-mix(in oklab, var(--ground) 82%, transparent); backdrop-filter: saturate(1.2) blur(10px); }
}

.mp-masthead__bar {
  display: flex;
  align-items: center;
  gap: 20px;
  min-height: 60px;
}

.mp-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--ink);
  flex: none;
}
.mp-brand:hover { color: var(--ink); }
.mp-brand__mark { width: 30px; height: 30px; color: var(--c-bolsa); }
.mp-brand__name {
  font-weight: 800;
  font-size: 1.12rem;
  letter-spacing: -0.02em;
  font-variation-settings: "wdth" 118;
  line-height: 1;
}

.mp-nav { display: flex; align-items: center; gap: 2px; margin-left: 8px; }
.mp-nav a {
  padding: 8px 10px;
  border-radius: var(--radius);
  color: var(--ink-2);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.92rem;
}
.mp-nav a:hover { color: var(--ink); background: var(--sheet-2); }
.mp-nav a.is-active, .mp-nav a[aria-current="page"] { color: var(--ink); box-shadow: inset 0 -2px 0 var(--ink); border-radius: 0; }

.mp-masthead__tools { display: flex; align-items: center; gap: 6px; margin-left: auto; }

.mp-switch {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--sheet);
}
.mp-switch button {
  min-height: 32px;
  padding: 0 12px;
  border: 0;
  border-radius: 1px;
  background: transparent;
  color: var(--ink-2);
  font-weight: 650;
  font-size: 0.86rem;
  cursor: pointer;
}
.mp-switch button.is-active { background: var(--ink); color: var(--sheet); }

.mp-menu-btn { display: none; }

@media (max-width: 980px) {
  .mp-nav {
    position: absolute;
    top: 100%;
    left: 0; right: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    margin: 0;
    padding: 8px var(--gutter) 14px;
    background: var(--ground);
    border-bottom: 1px solid var(--rule);
    box-shadow: 0 18px 30px -24px rgba(0, 0, 0, 0.5);
    display: none;
  }
  .mp-nav.is-open { display: flex; }
  .mp-nav a { padding: 13px 4px; border-bottom: 1px solid var(--rule-2); border-radius: 0; font-size: 1rem; }
  .mp-nav a.is-active { box-shadow: none; }
  .mp-menu-btn { display: inline-grid; }
}

@media (max-width: 560px) {
  .mp-masthead__bar { gap: 10px; min-height: 56px; }
  .mp-hide-sm { display: none !important; }
  .mp-brand__name { font-size: 1.02rem; }
}

/* ---------- Guilloche ---------- */

.mp-guilloche { width: 100%; height: 100%; overflow: visible; }
.mp-guilloche path { fill: none; vector-effect: non-scaling-stroke; }
.mp-guilloche .g-a { stroke: var(--gc, var(--c-bolsa)); stroke-width: 0.7; opacity: 0.85; }
.mp-guilloche .g-b { stroke: var(--gc2, var(--c-stable)); stroke-width: 0.5; opacity: 0.45; }
.mp-guilloche .g-axis { stroke: var(--rule); stroke-width: 1; stroke-dasharray: 2 3; }

.mp-guilloche.is-engraving path.g-a,
.mp-guilloche.is-engraving path.g-b {
  stroke-dasharray: var(--len) var(--len);
  stroke-dashoffset: var(--len);
  animation: mp-engrave 1.4s var(--ease) forwards;
}
.mp-guilloche.is-engraving path.g-b { animation-delay: 0.18s; }
@keyframes mp-engrave { to { stroke-dashoffset: 0; } }

.mp-rosette { position: absolute; pointer-events: none; color: var(--cls, var(--c-bolsa)); opacity: 0.16; }
.mp-rosette path { fill: none; stroke: currentColor; stroke-width: 0.6; vector-effect: non-scaling-stroke; }

/* ---------- Rodapé ---------- */

.mp-footer { margin-top: 56px; padding: 28px 0 40px; border-top: 1px solid var(--rule); color: var(--ink-2); font-size: 0.9rem; }
.mp-footer__grid { display: grid; gap: 20px; grid-template-columns: 1fr; }
.mp-footer a { color: var(--ink); }
.mp-footer__links { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.mp-disclaimer { max-width: 70ch; margin: 0; }
@media (min-width: 800px) { .mp-footer__grid { grid-template-columns: 1.4fr 1fr; align-items: start; } }

/* ---------- Toast ---------- */

.mp-toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  z-index: 80;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 10px 10px 16px;
  background: var(--ink);
  color: var(--sheet);
  border-radius: var(--radius);
  box-shadow: 0 16px 30px -16px rgba(0, 0, 0, 0.6);
  font-weight: 600;
  max-width: calc(100vw - 32px);
}
.mp-toast button { min-height: 36px; border: 1px solid color-mix(in oklab, var(--sheet) 40%, transparent); background: transparent; color: var(--sheet); border-radius: var(--radius); padding: 0 12px; cursor: pointer; font-weight: 650; }

/* ---------- Movimento ---------- */

.mp-settle { animation: mp-settle 700ms var(--ease) both; }
@keyframes mp-settle { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-delay: 0ms !important; transition-duration: 1ms !important; scroll-behavior: auto !important; }
  .mp-guilloche.is-engraving path { stroke-dasharray: none !important; stroke-dashoffset: 0 !important; }
}
