/* AMT Journal — gráficos (core/charts.js). Solo tokens: color de serie en --s, superficie en --chart-surface. */

.chart {
  position: relative;
  --chart-surface: var(--bg-1);
  border-radius: var(--r-sm);
  -webkit-tap-highlight-color: transparent;
}
.chart-plot { position: relative; touch-action: pan-y; }
.ch-svg, .ch-spark, .ch-ring { display: block; overflow: visible; }
.ch-svg { user-select: none; -webkit-user-select: none; }
.ch-svg text, .ch-ring text {
  font-family: var(--sans);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1, "cv11" 1, "ss01" 1;
}

/* ---------- color de serie ---------- */
.ch-s-c1 { --s: var(--c1); }
.ch-s-c2 { --s: var(--c2); }
.ch-s-c3 { --s: var(--c3); }
.ch-s-c4 { --s: var(--c4); }
.ch-s-c5 { --s: var(--c5); }
.ch-s-c6 { --s: var(--c6); }
.ch-s-c7 { --s: var(--c7); }
.ch-s-pos { --s: var(--pos); }
.ch-s-neg { --s: var(--neg); }
.ch-s-warn { --s: var(--warn); }
.ch-s-blue { --s: var(--blue); }
.ch-s-neutral { --s: var(--text-3); }

/* ---------- rejilla, ejes y rótulos ---------- */
.ch-grid line { stroke: var(--line-soft); stroke-width: 1; stroke-dasharray: 2 4; shape-rendering: crispEdges; }
.ch-zero { stroke: var(--line-strong); stroke-width: 1; shape-rendering: crispEdges; }
.ch-ticks text, .ch-axis-title { font-size: 10.5px; font-weight: 500; fill: var(--text-3); }
.ch-axis-title { letter-spacing: .01em; }
.ch-cats text { font-size: 12px; font-weight: 500; fill: var(--text-2); }
.ch-rowlabels text { font-size: 11px; font-weight: 500; fill: var(--text-3); }
.ch-vals text { font-size: 10.5px; font-weight: 500; fill: var(--text-2); }
.ch-empty-text { font-size: 12px; font-weight: 500; fill: var(--text-3); }

/* ---------- líneas y áreas ---------- */
.ch-line { fill: none; stroke: var(--s, var(--c1)); stroke-width: 1.5; stroke-linejoin: round; stroke-linecap: round; }
.ch-line.is-dashed { stroke-dasharray: 4 4; stroke-linecap: butt; }
.ch-stop-1 { stop-color: var(--s, var(--c1)); stop-opacity: .2; }
.ch-stop-0 { stop-color: var(--s, var(--c1)); stop-opacity: 0; }
.ch-stop-hi { stop-color: var(--s, var(--c1)); stop-opacity: .26; }
.ch-stop-lo { stop-color: var(--s, var(--c1)); stop-opacity: .045; }
.ch-end { fill: var(--s, var(--c1)); stroke: var(--chart-surface, var(--bg-1)); stroke-width: 1.5; }

.ch-ref { stroke: var(--s); stroke-width: 1; stroke-dasharray: 4 4; stroke-opacity: .7; shape-rendering: crispEdges; }
.ch-ref.is-base { stroke: var(--line-strong); stroke-dasharray: 2 3; stroke-opacity: 1; }
.ch-ref-label {
  font-size: 10.5px; font-weight: 500; fill: var(--s);
  paint-order: stroke; stroke: var(--chart-surface); stroke-width: 4px; stroke-linejoin: round;
}

/* leyenda de series (opts.legend) */
.chart-keys { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-bottom: 10px; font-size: 12px; color: var(--text-2); }
.chart-keys span { display: inline-flex; align-items: center; gap: 7px; min-width: 0; }
.chart-key { flex: none; width: 12px; height: 2px; border-radius: 2px; background: var(--s, var(--c1)); }
.chart-key.is-dashed { background: repeating-linear-gradient(90deg, var(--s, var(--c1)) 0 4px, transparent 4px 7px); }

/* hover: cursor vertical + puntos con anillo de superficie */
.ch-hover { opacity: 0; transition: opacity .12s ease; pointer-events: none; }
.ch-hover.is-on { opacity: 1; }
.ch-cross { stroke: var(--line-strong); stroke-width: 1; shape-rendering: crispEdges; }
.ch-dot { fill: var(--s, var(--c1)); stroke: var(--chart-surface); stroke-width: 2; }

/* ---------- barras ---------- */
.ch-bar { fill: var(--s, var(--c1)); transition: opacity .15s ease; }
.ch-bars.has-active .ch-bar:not(.is-active) { opacity: .45; }
.chart-hist .ch-bar { fill-opacity: .8; }
.ch-band { fill: var(--hover); opacity: 0; transition: opacity .12s ease; pointer-events: none; }
.ch-band.is-on { opacity: 1; }

/* ---------- sparkline y ring ---------- */
.ch-spark { flex: none; }
.ch-spark-empty { stroke: var(--line-strong); stroke-width: 1; stroke-dasharray: 2 3; shape-rendering: crispEdges; }
.ch-ring { flex: none; }
.ch-ring-track { fill: none; stroke: var(--s, var(--c1)); stroke-opacity: .16; }
.ch-ring-val { fill: none; stroke: var(--s, var(--c1)); stroke-linecap: round; }
.ch-ring-label { fill: var(--text); font-weight: 600; letter-spacing: -.02em; }

/* ---------- donut ---------- */
.chart-donut .chart-plot { display: flex; align-items: center; flex-wrap: wrap; gap: 14px 28px; }
.ch-donut { flex: none; }
.ch-donut-track { fill: none; stroke: var(--line-soft); }
.ch-arc { fill: none; stroke: var(--s, var(--c1)); transition: opacity .15s ease; }
.ch-arcs.has-active .ch-arc:not(.is-active) { opacity: .35; }
.ch-donut-value { fill: var(--text); font-weight: 600; letter-spacing: -.03em; }
.ch-donut-label { fill: var(--text-3); font-size: 10.5px; font-weight: 500; }

.chart-legend { list-style: none; flex: 1 1 150px; min-width: 0; display: grid; gap: 9px; font-size: 12.5px; }
.chart-legend li { display: grid; grid-template-columns: 8px minmax(0, 1fr) auto 38px; align-items: center; gap: 10px; }
.chart-legend-key { width: 8px; height: 8px; border-radius: 2px; background: var(--s, var(--c1)); }
.chart-legend-label { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chart-legend-val { color: var(--text); font-weight: 500; }
.chart-legend-pct { color: var(--text-3); text-align: right; }

/* ---------- heatmap ---------- */
.ch-cell { fill: var(--s); }
.ch-cell.is-empty { fill: rgba(255, 255, 255, .028); }
.ch-cell-focus { fill: none; stroke: var(--text-2); stroke-width: 1; opacity: 0; pointer-events: none; }
.ch-cell-focus.is-on { opacity: 1; }

/* ---------- scatter ---------- */
.ch-pt { fill: var(--s, var(--c1)); fill-opacity: .42; stroke: var(--s, var(--c1)); stroke-opacity: .95; stroke-width: 1; }
.ch-pt-focus { fill: var(--s, var(--c1)); fill-opacity: .18; stroke: var(--s, var(--c1)); stroke-width: 1.25; opacity: 0; pointer-events: none; }
.ch-pt-focus.is-on { opacity: 1; }

/* ---------- tooltip ---------- */
.chart-tip {
  position: absolute; left: 0; top: 0; z-index: 5;
  min-width: 92px; max-width: min(280px, calc(100% - 4px));
  padding: 8px 10px 9px;
  background: var(--bg-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-pop);
  color: var(--text);
  font-size: 12px; line-height: 1.35;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0; visibility: hidden;
  transition: opacity .12s ease, visibility 0s linear .12s;
  will-change: transform;
}
.chart-tip.is-on { opacity: 1; visibility: visible; transition: opacity .12s ease, transform .14s var(--ease); }
.chart-tip-title { color: var(--text-3); font-size: 11px; font-weight: 500; margin-bottom: 5px; overflow: hidden; text-overflow: ellipsis; }
.chart-tip-title::first-letter { text-transform: uppercase; }
.chart-tip-row { display: flex; align-items: center; gap: 7px; }
.chart-tip-row + .chart-tip-row { margin-top: 3px; }
.chart-tip-key { flex: none; width: 10px; height: 2px; border-radius: 2px; background: var(--s, var(--c1)); }
.chart-tip-name { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; }
.chart-tip-val { margin-left: auto; padding-left: 10px; font-weight: 600; color: var(--text); }
.chart-tip-val:first-child, .chart-tip-key + .chart-tip-val { margin-left: 0; padding-left: 0; }
.chart-tip-val.pos { color: var(--pos); }
.chart-tip-val.neg { color: var(--neg); }
.chart-tip-sub { margin-top: 4px; color: var(--text-3); font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; }

/* ---------- calendario ---------- */
.ch-cal { --cal-gap: 6px; --cal-h: 78px; --cal-cols: repeat(7, minmax(0, 1fr)); }
.ch-cal[data-totals] { --cal-cols: repeat(7, minmax(0, 1fr)) minmax(0, 1.1fr); }
.ch-cal-head, .ch-cal-grid { display: grid; grid-template-columns: var(--cal-cols); gap: var(--cal-gap); }
.ch-cal-head { margin-bottom: 8px; }
.ch-cal-head span {
  padding-left: 9px;
  font-size: 10.5px; font-weight: 600; letter-spacing: .11em; text-transform: uppercase; color: var(--text-3);
  overflow: hidden; white-space: nowrap;
}
.ch-cal-grid { grid-auto-rows: var(--cal-h); }

.ch-cal-day, .ch-cal-total {
  position: relative;
  display: flex; flex-direction: column; align-items: flex-start;
  min-width: 0; padding: 8px 9px 8px;
  border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
  background: transparent;
  color: var(--text);
  font: inherit; text-align: left;
  overflow: hidden;
  transition: border-color .15s ease, background .15s ease;
}
button.ch-cal-day { cursor: pointer; }
.ch-cal-day > *, .ch-cal-total > * { position: relative; max-width: 100%; }
.ch-cal-day.is-out { border-color: transparent; background: rgba(255, 255, 255, .012); }

/* tinte por signo y magnitud: capa de color con opacidad --a (alfa del token, sin hex nuevos) */
.ch-cal-day::before {
  content: ""; position: absolute; inset: 0;
  background: var(--tint, transparent); opacity: var(--a, 0);
  pointer-events: none;
}
.ch-cal-day.is-pos { --tint: var(--pos); border-color: rgba(62, 207, 142, .16); }
.ch-cal-day.is-neg { --tint: var(--neg); border-color: rgba(240, 97, 109, .16); }
.ch-cal-day.is-flat { background: var(--hover); }
.ch-cal-day.is-pos:hover, .ch-cal-day.is-pos:focus-visible { border-color: var(--pos-line); }
.ch-cal-day.is-neg:hover, .ch-cal-day.is-neg:focus-visible { border-color: var(--neg-line); }
button.ch-cal-day.is-idle:hover, .ch-cal-day.is-flat:hover { border-color: var(--line-strong); background: var(--hover); }
.ch-cal-day.is-today { border-color: var(--blue-line); box-shadow: inset 0 0 0 1px var(--blue-line); }
.ch-cal-day.is-today:hover { border-color: var(--blue); }
.ch-cal-day:focus-visible { outline-offset: 1px; }

.ch-cal-num { font-size: 11px; font-weight: 500; line-height: 1; color: var(--text-3); }
.is-idle > .ch-cal-num { color: var(--text-4); }
.is-today > .ch-cal-num { color: var(--blue); font-weight: 600; }
.ch-cal-pnl {
  margin-top: auto;
  font-size: 13px; font-weight: 600; line-height: 1.2; letter-spacing: -.015em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.is-pos > .ch-cal-pnl { color: var(--pos); }
.is-neg > .ch-cal-pnl { color: var(--neg); }
.is-flat > .ch-cal-pnl { color: var(--text-2); }
.ch-cal-count {
  margin-top: 2px;
  font-size: 10.5px; line-height: 1.2; color: var(--text-3);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* total semanal: pozo neutro, separado de los días */
.ch-cal-total { border-color: transparent; background: rgba(255, 255, 255, .028); }
.ch-cal-total > .ch-cal-num { color: var(--text-4); }
.ch-cal-total > .ch-cal-num::before { content: "#"; opacity: .7; }

.ch-cal[data-size="md"] { --cal-gap: 5px; --cal-h: 64px; }
.ch-cal[data-size="md"] .ch-cal-day, .ch-cal[data-size="md"] .ch-cal-total { padding: 7px 7px 7px; border-radius: var(--r-sm); }
.ch-cal[data-size="md"] .ch-cal-pnl { font-size: 12px; }
.ch-cal[data-size="md"] .ch-cal-count { display: none; }
.ch-cal[data-size="md"] .ch-cal-head span { padding-left: 7px; letter-spacing: .08em; }

.ch-cal[data-size="sm"] { --cal-gap: 4px; --cal-h: 50px; --cal-cols: repeat(7, minmax(0, 1fr)); }
.ch-cal[data-size="sm"] .ch-cal-total, .ch-cal[data-size="sm"] .ch-cal-wk { display: none; }
.ch-cal[data-size="sm"] .ch-cal-day { padding: 5px 4px 5px 5px; border-radius: var(--r-xs); }
.ch-cal[data-size="sm"] .ch-cal-num { font-size: 10px; }
.ch-cal[data-size="sm"] .ch-cal-pnl { font-size: 10.5px; letter-spacing: -.03em; }
.ch-cal[data-size="sm"] .ch-cal-count { display: none; }
.ch-cal[data-size="sm"] .ch-cal-head span { padding-left: 4px; font-size: 9.5px; letter-spacing: .06em; }

/* ---------- animación de entrada (≤ 600 ms) ---------- */
@keyframes ch-draw { from { stroke-dashoffset: 1.03; } to { stroke-dashoffset: 0; } }
@keyframes ch-fade { from { opacity: 0; } }
@keyframes ch-grow-y { from { transform: scaleY(0); } }
@keyframes ch-grow-x { from { transform: scaleX(0); } }
@keyframes ch-cal-in { from { opacity: 0; transform: translateY(4px); } }

.ch-draw { stroke-dasharray: 1.02 3; animation: ch-draw .6s cubic-bezier(.45, 0, .2, 1) both; }
.ch-fade { animation: ch-fade .45s ease .12s both; }
.ch-pop { animation: ch-fade .2s ease .4s both; }
.ch-grow, .ch-grow-x { transform-box: fill-box; transform-origin: 50% 100%; animation: ch-grow-y .42s var(--ease) both; }
.ch-grow.is-neg { transform-origin: 50% 0; }
.ch-grow-x { transform-origin: 0 50%; animation-name: ch-grow-x; }
.ch-grow-x.is-neg { transform-origin: 100% 50%; }
.ch-cal-in { animation: ch-cal-in .32s var(--ease) both; }

@media (prefers-reduced-motion: reduce) {
  .ch-draw, .ch-fade, .ch-pop, .ch-grow, .ch-grow-x, .ch-cal-in { animation: none; }
  .chart-tip, .chart-tip.is-on { transition: none; }
}
