/* UPX Charts · estilos dos gráficos.
   Só classes .upx-ch-* e tokens do app (--text, --text2, --text3, --border, --surface2,
   --card-bg, --ok-*, --bad-*, --warn-*). Nada global: pode entrar em qualquer tela.

   Paleta categórica (ordem validada, vizinhos separados para daltonismo):
   azul · rosa · âmbar · verde · violeta · ciano.
   Claro: tons escuros dos agentes (tabela agentBubble do app), ≥ 3:1 sobre o fundo claro.
   Escuro: tons sólidos dos agentes (#5B9BE0 …), ≥ 3:1 sobre #00121A. */

.upx-ch {
  --ch-blue: #2576CE; --ch-rose: #C3487E; --ch-amber: #A66512;
  --ch-green: #0C8367; --ch-violet: #7565C9; --ch-cyan: #0A7F93;
  --ch-other: var(--text3);
  --ch-muted: var(--text3);
  --ch-ok: var(--green); --ch-warn: var(--amber); --ch-bad: var(--red);
  --ch-grid: var(--border);
  --ch-track: var(--surface2);
  /* Anel de 2px em volta de pontos: a cor da superfície onde o gráfico está. */
  --ch-ring: var(--card-solid);
  --ch-tip-bg: var(--card-solid);
  position: relative;
  min-width: 0;
  color: var(--text);
  font-family: Roboto, system-ui, -apple-system, "Segoe UI", sans-serif;
}
[data-theme="dark"] .upx-ch, .upx-ch[data-theme="dark"] {
  --ch-blue: #5B9BE0; --ch-rose: #E07AA6; --ch-amber: #E8A54E;
  --ch-green: #3CBFA0; --ch-violet: #9A8BE6; --ch-cyan: #3CB8CC;
}

/* ── Estrutura ── */
.upx-ch-plot { position: relative; width: 100%; border-radius: 0.75rem; outline: none; touch-action: pan-y; }
.upx-ch-plot:focus-visible { box-shadow: 0 0 0 2px var(--text3); }
.upx-ch-plot > svg { display: block; overflow: visible; }
.upx-ch-sr { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ── Eixos e grade (recessivos: linha fina, cor da borda) ── */
.upx-ch-gridline { stroke: var(--ch-grid); stroke-width: 1; shape-rendering: crispEdges; }
.upx-ch-gridline.is-zero { stroke: var(--text3); opacity: .5; }
.upx-ch-tick { fill: var(--text3); font-size: 0.75rem; font-variant-numeric: tabular-nums; }
.upx-ch-cat { fill: var(--text2); font-size: 0.8125rem; }
.upx-ch-refline { stroke: var(--text3); stroke-width: 1; stroke-dasharray: 4 4; opacity: .8; }

/* ── Marcas ── */
.upx-ch-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; transition: opacity .3s; }
.upx-ch-line--spark { stroke-width: 1.75; }
.upx-ch-area { stroke: none; transition: opacity .3s; }
.upx-ch-dot { stroke: var(--ch-ring); stroke-width: 2; paint-order: stroke; }
.upx-ch-dots .upx-ch-dot, .upx-ch-labels, .upx-ch-enddot { opacity: 0; transform-box: fill-box; transform-origin: center; transform: scale(.4); transition: opacity .3s, transform .45s cubic-bezier(.2,.9,.25,1.15); }
svg.is-in .upx-ch-dots .upx-ch-dot, svg.is-in .upx-ch-labels, svg.is-in .upx-ch-enddot { opacity: 1; transform: none; }
.upx-ch-labels { transform: none; }
.upx-ch-dot.is-active { r: 5; }
.upx-ch-cross circle.is-active { animation: upx-ch-pop .22s cubic-bezier(.2,.9,.25,1.15) both; }
svg > circle.is-active { opacity: 0; transition: opacity .15s; }
svg > circle.is-active.is-on { opacity: 1; }
.upx-ch-extreme { fill: var(--text3); stroke-width: 1.5; }
.upx-ch-cross line, .upx-ch-cross { stroke: var(--text3); stroke-width: 1; opacity: 0; transition: opacity .15s; shape-rendering: crispEdges; }
.upx-ch-cross.is-on { opacity: .6; }
.upx-ch-cross circle { opacity: 1; }
.upx-ch-hit { fill: transparent; cursor: crosshair; }
.upx-ch-hits .upx-ch-hit { cursor: default; }
.upx-ch-bar, .upx-ch-slice { transition: opacity .2s; }
.upx-ch-bar.is-dim, .upx-ch-slice.is-dim { opacity: .38; }
.upx-ch-slice { cursor: default; }
.upx-ch-vlabel, .upx-ch-endlabel { fill: var(--text2); font-size: 0.75rem; font-variant-numeric: tabular-nums; }
.upx-ch-endlabel { fill: var(--text); font-weight: 500; }
.upx-ch-track { fill: none; stroke: var(--ch-track); stroke-linecap: round; }
.upx-ch-fill { fill: none; stroke-linecap: round; transition: stroke .4s; }
.upx-ch-pulse { opacity: .5; transform-box: fill-box; transform-origin: center; animation: upx-ch-pulse 1.8s cubic-bezier(.22,1,.36,1) infinite; }

/* ── Tooltip (vidro sólido, como os menus que abrem por cima) ── */
.upx-ch-tip { position: absolute; left: 0; top: 0; z-index: 3; min-width: 8.75rem; max-width: 16.25rem; padding: 0.625rem 0.75rem; border-radius: 0.75rem; background: var(--ch-tip-bg); border: 1px solid var(--border); box-shadow: 0 0.75rem 2rem rgba(0,18,26,.18); color: var(--text); font-size: 0.8125rem; line-height: 1.125rem; pointer-events: none; opacity: 0; transition: opacity .16s, transform .22s cubic-bezier(.22,1,.36,1); }
.upx-ch-tip.is-on { opacity: 1; }
.upx-ch-tip-t { margin-bottom: 0.375rem; font-size: 0.75rem; color: var(--text3); }
.upx-ch-tip-r { display: flex; align-items: center; gap: 0.5rem; }
.upx-ch-tip-r + .upx-ch-tip-r { margin-top: 0.25rem; }
.upx-ch-tip-r i { width: 0.5rem; height: 0.5rem; flex: none; border-radius: 50%; }
.upx-ch-tip-r span { flex: 1; color: var(--text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.upx-ch-tip-r b { font-weight: 500; font-variant-numeric: tabular-nums; }
.upx-ch-tip-f { margin-top: 0.5rem; padding-top: 0.375rem; border-top: 1px solid var(--border); color: var(--text2); font-variant-numeric: tabular-nums; }

/* ── Legenda em chips (texto em token de texto; a cor vai no ponto) ── */
.upx-ch-legend { display: flex; flex-wrap: wrap; gap: 0.375rem; margin-bottom: 0.75rem; }
.upx-ch-legend[hidden] { display: none; }
.upx-ch-chip { display: inline-flex; align-items: center; gap: 0.375rem; height: 1.875rem; padding: 0 0.625rem; border: 0; border-radius: 62.4375rem; background: transparent; color: var(--text2); font: inherit; font-size: 0.8125rem; line-height: 1; transition: background .15s, color .15s, opacity .2s; }
button.upx-ch-chip { cursor: pointer; }
button.upx-ch-chip:hover { background: var(--card-bg); color: var(--text); }
.upx-ch-chip i { width: 0.5rem; height: 0.5rem; border-radius: 50%; flex: none; transition: transform .2s; }
.upx-ch-chip b { font-weight: 500; color: var(--text); font-variant-numeric: tabular-nums; }
.upx-ch-chip.is-off { opacity: .45; }
.upx-ch-chip.is-off i { transform: scale(.6); }

/* ── Rosca, pizza, anel e medidor ── */
.upx-ch--radial { display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap; }
.upx-ch--radial > .upx-ch-plot { flex: none; }
.upx-ch--radial > .upx-ch-legend { flex-direction: column; align-items: flex-start; gap: 2px; margin: 0; flex: 1; min-width: 10rem; }
.upx-ch--radial > .upx-ch-legend .upx-ch-chip { width: 100%; padding: 0; }
.upx-ch--radial > .upx-ch-legend .upx-ch-chip span { flex: 1; }
.upx-ch-center { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); display: flex; flex-direction: column; align-items: center; text-align: center; pointer-events: none; }
.upx-ch-center.is-gauge { transform: translate(-50%, -58%); }
.upx-ch-center b { font-size: 1.25rem; line-height: 1.75rem; font-weight: 600; letter-spacing: -.01em; }
.upx-ch-center span { font-size: 0.75rem; line-height: 1rem; color: var(--text3); }

/* ── Tempo real ── */
.upx-ch-badge { position: absolute; left: 0; top: 0; height: 1.5rem; padding: 0 0.5rem; border-radius: 62.4375rem; background: var(--text); color: var(--bg); font-size: 0.75rem; line-height: 1.5rem; font-weight: 500; font-variant-numeric: tabular-nums; white-space: nowrap; pointer-events: none; }
.upx-ch-badge[data-dir="up"] { background: var(--ok-bg); color: var(--ok-fg); }
.upx-ch-badge[data-dir="down"] { background: var(--bad-bg); color: var(--bad-fg); }

/* ── Barra de progresso ── */
.upx-ch-progress { display: flex; flex-direction: column; gap: 0.5rem; }
.upx-ch-progress-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 2px 0.75rem; font-size: 0.875rem; line-height: 1.25rem; }
.upx-ch-progress-head:empty, .upx-ch-progress-label:empty + .upx-ch-progress-cap:empty { display: none; }
.upx-ch-progress-cap { white-space: nowrap; color: var(--text2); font-size: 0.8125rem; font-variant-numeric: tabular-nums; }
.upx-ch-progress-track { display: flex; gap: 2px; height: 0.625rem; border-radius: 62.4375rem; background: var(--ch-track); overflow: hidden; }
.upx-ch-progress[data-size="sm"] .upx-ch-progress-track { height: 0.375rem; }
.upx-ch-progress[data-size="lg"] .upx-ch-progress-track { height: 0.875rem; }
.upx-ch-progress-fill { flex: 0 0 0%; min-width: 0; transition-property: flex-basis, transform, opacity, background-color; transition-timing-function: cubic-bezier(.22,1,.36,1); }
.upx-ch-progress-fill:last-child { border-radius: 0 62.4375rem 62.4375rem 0; }
.upx-ch-progress-track.is-steps { gap: 0.25rem; background: transparent; border-radius: 0; overflow: visible; }
.upx-ch-progress-track.is-steps .upx-ch-progress-fill { flex-grow: 1; border-radius: 62.4375rem; transform-origin: left; }
.upx-ch-progress-track.is-steps .upx-ch-progress-fill.is-empty { background: var(--ch-track) !important; }
.upx-ch-progress-track.is-steps .upx-ch-progress-fill.is-pre:not(.is-empty) { transform: scaleX(0); }
.upx-ch-progress > .upx-ch-legend { margin: 0.25rem 0 0; }
.upx-ch-progress > .upx-ch-legend .upx-ch-chip { padding: 0 0.625rem 0 0; height: 1.375rem; }

/* ── Cartões de indicador ── */
/* Cartão dentro de outra superfície de vidro (painel da home, resultado do chat): vidro sobre vidro vira branco.
   Aninhado, fica sólido e com raio 12, como as métricas dos painéis (design system, 03/11/2026). */
.upx-ch-nested .upx-ch-card, .upx-ch-card.is-nested { background: var(--card-solid); -webkit-backdrop-filter: none; backdrop-filter: none; border-radius: 0.75rem; padding: 0.75rem; }
.upx-ch-card { display: flex; flex-direction: column; gap: 0.375rem; min-width: 0; padding: 1rem; border-radius: 1rem; background: var(--card-bg); -webkit-backdrop-filter: blur(1rem); backdrop-filter: blur(1rem); }
.upx-ch-kpi-label { font-size: 0.8125rem; line-height: 1.125rem; color: var(--text2); }
.upx-ch-kpi-value { font-size: 1.625rem; line-height: 2rem; font-weight: 600; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.upx-ch-kpi[data-variant="compact"] { padding: 0.75rem 0.875rem; gap: 2px; }
.upx-ch-kpi[data-variant="compact"] .upx-ch-kpi-value { font-size: 1.25rem; line-height: 1.75rem; }
.upx-ch-kpi[data-variant="hero"] .upx-ch-kpi-value { font-size: 3rem; line-height: 3.375rem; letter-spacing: -.02em; }
.upx-ch-kpi-foot { display: flex; align-items: center; flex-wrap: wrap; gap: 0.5rem; font-size: 0.75rem; line-height: 1rem; color: var(--text3); }
.upx-ch-kpi-foot:empty { display: none; }
.upx-ch-kpi-spark { margin-top: 0.375rem; }
.upx-ch-num { font-variant-numeric: proportional-nums; }
.upx-ch-num.is-counting { font-variant-numeric: tabular-nums; }
.upx-ch-delta { display: inline-flex; align-items: center; gap: 0.1875rem; height: 1.375rem; padding: 0 0.5rem; border-radius: 62.4375rem; font-size: 0.75rem; font-weight: 500; font-variant-numeric: tabular-nums; white-space: nowrap; background: var(--surface); color: var(--text2); }
.upx-ch-delta[data-tone="good"] { background: var(--ok-bg); color: var(--ok-fg); }
.upx-ch-delta[data-tone="bad"] { background: var(--bad-bg); color: var(--bad-fg); }
.upx-ch-cmp { gap: 0.75rem; }
.upx-ch-cmp-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.upx-ch-cmp-row { display: grid; grid-template-columns: 1fr auto; gap: 0.25rem 0.75rem; align-items: baseline; }
.upx-ch-cmp-name { font-size: 0.8125rem; color: var(--text2); }
.upx-ch-cmp-row b { font-size: 1rem; line-height: 1.5rem; font-weight: 600; text-align: right; }
.upx-ch-cmp-row[data-k="p"] b { font-weight: 500; color: var(--text2); }
.upx-ch-cmp-bar { grid-column: 1 / -1; display: flex; height: 0.5rem; border-radius: 62.4375rem; background: var(--ch-track); overflow: hidden; }
.upx-ch-cmp-bar i { flex: 0 0 0%; border-radius: 62.4375rem; transition-property: flex-basis; transition-timing-function: cubic-bezier(.22,1,.36,1); }
.upx-ch-stat { gap: 0.625rem; }
.upx-ch-stat-head { display: flex; align-items: baseline; gap: 0.625rem; flex-wrap: wrap; }
.upx-ch-stat-head span { font-size: 0.75rem; color: var(--text3); }
.upx-ch-stat-strip svg { display: block; overflow: visible; }
.upx-ch-stat-iqr { fill: var(--ch-track); }
.upx-ch-stat-med { stroke: var(--text); stroke-width: 2; stroke-linecap: round; }
.upx-ch-stat-dot { opacity: .75; animation: upx-ch-fade .4s cubic-bezier(.22,1,.36,1) both; }
.upx-ch-stat-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 0.5rem; margin: 0; }
.upx-ch-stat-grid div { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.upx-ch-stat-grid dt { font-size: 0.75rem; line-height: 1rem; color: var(--text3); }
.upx-ch-stat-grid dd { margin: 0; font-size: 0.875rem; line-height: 1.25rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Avançados (v0.2) ── */
.upx-ch-gridline.is-soft { opacity: .6; }
.upx-ch-axistitle { fill: var(--text3); font-size: 0.75rem; }
.upx-ch-point { r: 5; }
.upx-ch-bubble { fill-opacity: .55; stroke: var(--ch-ring); stroke-width: 1.5; transition: opacity .2s; }
.upx-ch-point, .upx-ch-bubble { transition: opacity .2s; }
.upx-ch-point.is-dim, .upx-ch-bubble.is-dim { opacity: .3 !important; }
.upx-ch-focusring { fill: none; stroke: var(--text); stroke-width: 1.5; pointer-events: none; animation: upx-ch-fade .15s both; }
.upx-ch-rring { fill: none; stroke: var(--ch-grid); stroke-width: 1; }
.upx-ch-raxes .is-on .upx-ch-gridline { stroke: var(--text3); }
.upx-ch-raxes .is-on .upx-ch-cat { fill: var(--text); }
.upx-ch-rshape { fill-opacity: .14; stroke-width: 2; stroke-linejoin: round; transition: opacity .3s; }
.upx-ch-cell { transition: fill .5s cubic-bezier(.22,1,.36,1), opacity .2s; }
.upx-ch-cell.is-dim { opacity: .55 !important; }
.upx-ch-cellfocus { fill: none; stroke: var(--text); stroke-width: 1.5; pointer-events: none; }
.upx-ch-ramp { display: flex; align-items: center; gap: 2px; margin-top: 0.625rem; font-size: 0.75rem; color: var(--text3); font-variant-numeric: tabular-nums; }
.upx-ch-ramp i { width: 1.75rem; height: 0.625rem; border-radius: 0.1875rem; }
.upx-ch-ramp-l:first-child { margin-right: 0.375rem; }
.upx-ch-ramp-l:last-child { margin-left: 0.375rem; }
.upx-ch-tile { transition: opacity .2s; }
.upx-ch-tile.is-dim { opacity: .45; }
.upx-ch-tile text { pointer-events: none; font-variant-numeric: tabular-nums; }
.upx-ch-tile-l { font-size: 0.8125rem; font-weight: 500; }
.upx-ch-tile-v { font-size: 0.75rem; }
.upx-ch-tile[data-ink="on"] text { fill: #fff; }
[data-theme="dark"] .upx-ch-tile[data-ink="on"] text { fill: #00121A; }
.upx-ch-tile[data-ink="soft"] text { fill: var(--text); }
.upx-ch-neck { fill: var(--ch-track); opacity: .7; }
.upx-ch-fval { fill: var(--text); font-size: 0.8125rem; font-weight: 500; font-variant-numeric: tabular-nums; }
.upx-ch-fval.is-in { fill: #fff; }
[data-theme="dark"] .upx-ch-fval.is-in { fill: #00121A; }
.upx-ch-conv { fill: var(--text2); font-size: 0.75rem; font-variant-numeric: tabular-nums; }
.upx-ch-link { stroke: var(--text3); stroke-width: 1; stroke-dasharray: 3 3; transition: opacity .2s; }
.upx-ch-vlabel.is-total { fill: var(--text); font-weight: 500; }
.upx-ch-candle line { stroke-width: 1; }
.upx-ch-candle { transition: opacity .2s; }
.upx-ch-candle.is-dim { opacity: .4; }
.upx-ch-avg { stroke: var(--text3); stroke-width: 1.5; stroke-dasharray: none; }

/* ── Financeiro (motor Lightweight Charts) ── */
.upx-ch-fin-legend { display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem 0.875rem; min-height: 1.5rem; margin-bottom: 0.5rem; font-size: 0.8125rem; line-height: 1.125rem; color: var(--text); font-variant-numeric: tabular-nums; }
.upx-ch-fin-legend b { font-weight: 600; }
.upx-ch-fin-legend i { font-style: normal; color: var(--text3); margin-right: 0.25rem; }
.upx-ch-fin-date { color: var(--text3); }
.upx-ch-fin-plot a { opacity: .55; transition: opacity .2s; }
.upx-ch-fin-plot a:hover { opacity: 1; }

/* ── Tabela visível (alternativa ao gráfico) ── */
.upx-ch-table:not(.upx-ch-sr) { margin-top: 0.75rem; overflow-x: auto; }
.upx-ch-table table { width: 100%; border-collapse: collapse; font-size: 0.8125rem; font-variant-numeric: tabular-nums; }
.upx-ch-table caption { text-align: left; font-size: 0.75rem; color: var(--text3); padding-bottom: 0.375rem; }
.upx-ch-table th, .upx-ch-table td { padding: 0.375rem 0.625rem; text-align: right; border-top: 1px solid var(--border); white-space: nowrap; }
.upx-ch-table th[scope="row"], .upx-ch-table thead th:first-child { text-align: left; font-weight: 400; color: var(--text2); }
.upx-ch-table thead th { font-weight: 400; font-size: 0.75rem; color: var(--text3); border-top: 0; }

@keyframes upx-ch-pulse { 0% { transform: scale(1); opacity: .5; } 80%, 100% { transform: scale(3.2); opacity: 0; } }
@keyframes upx-ch-pop { from { transform: scale(.4); } to { transform: none; } }
@keyframes upx-ch-fade { from { opacity: 0; } }

@media (max-width: 640px) {
  .upx-ch-stat-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .upx-ch--radial { gap: 1rem; }
}
@media (prefers-reduced-motion: reduce) {
  .upx-ch *, .upx-ch *::before, .upx-ch *::after { animation: none !important; transition-duration: 0s !important; transition-delay: 0s !important; }
  .upx-ch-pulse { display: none; }
}
@media (forced-colors: active) {
  .upx-ch-line { stroke: CanvasText !important; }
  .upx-ch-bar, .upx-ch-slice { fill: CanvasText !important; }
}
