/*
 * Gráficos y visuales de los paneles (js/ui/chart.js y js/demos/panels/*): líneas y puntos en SVG, barras,
 * mapas de calor, fichas de tokens, celdas de memoria, apilados y pilas de eventos del agente.
 */

/* ------------------------------------------------------------------ SVG */
.chart {
  display: block;
  width: 100%;
  height: 220px;
  overflow: visible;
}

.chart--tall {
  height: 280px;
}

.chart--short {
  height: 170px;
}

.chart__grid line {
  stroke: var(--c-grid);
  stroke-width: 1;
}

.chart__axis {
  stroke: var(--border-strong);
  stroke-width: 1.2;
}

.chart__tick,
.chart__axis-name,
.chart__label {
  fill: var(--text-muted);
  font-size: 10.5px;
  font-family: var(--font-mono);
}

.chart__axis-name {
  font-size: 11px;
  fill: var(--text-soft);
}

.chart__label {
  fill: var(--text);
  font-size: 11px;
  paint-order: stroke;
  stroke: var(--bg-elev);
  stroke-width: 3px;
  stroke-linejoin: round;
}

.chart__line {
  fill: none;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart__dot {
  stroke: var(--bg-elev);
  stroke-width: 1.5;
}

.chart__legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-3);
  font-size: 0.78rem;
  color: var(--text-muted);
}

.chart__legend span::before {
  content: '';
  display: inline-block;
  width: 14px;
  height: 3px;
  margin-right: 6px;
  vertical-align: middle;
  border-radius: 2px;
  background: var(--swatch, var(--accent));
}

/* ---------------------------------------------------------------- barras */
.hbars {
  display: grid;
  gap: 5px;
}

.hbar {
  display: grid;
  grid-template-columns: minmax(64px, 108px) minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-2);
  font-size: 0.82rem;
}

.hbar__label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-soft);
}

.hbar__track {
  position: relative;
  height: 14px;
  border-radius: 4px;
  background: var(--panel-2);
  overflow: hidden;
}

.hbar__fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: calc(var(--w, 0) * 100%);
  border-radius: 4px;
  background: var(--bar, var(--accent));
  transition: width 0.18s ease;
}

.hbar__ghost {
  position: absolute;
  inset: 0 auto 0 0;
  width: calc(var(--g, 0) * 100%);
  border-radius: 4px;
  background: var(--bar, var(--accent));
  opacity: 0.22;
}

.hbar__value {
  min-width: 4.6em;
  text-align: right;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text);
}

.hbar.is-off .hbar__label,
.hbar.is-off .hbar__value {
  color: var(--text-dim);
  text-decoration: line-through;
}

.hbar.is-hot .hbar__label {
  color: var(--text-strong);
  font-weight: 650;
}

.bars-v {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 110px;
  padding: 0 2px;
  border-bottom: 1px solid var(--border-strong);
}

.bars-v__bar {
  flex: 1 1 0;
  min-width: 3px;
  height: calc(var(--h, 0) * 100%);
  min-height: 1px;
  border-radius: 3px 3px 0 0;
  background: var(--bar, var(--accent));
  transition: height 0.18s ease;
}

.bars-v__bar.is-needle {
  outline: 2px solid var(--c-gold);
}

.bars-v__bar.is-dim {
  opacity: 0.28;
}

/* ----------------------------------------------------------- mapa de calor */
.heat {
  display: grid;
  gap: 2px;
  grid-template-columns: auto repeat(var(--cols, 2), minmax(34px, 1fr));
  align-items: stretch;
  font-family: var(--font-mono);
  font-size: 0.78rem;
}

.heat__head {
  padding: 3px 4px;
  color: var(--text-muted);
  text-align: center;
  align-self: center;
}

.heat__head--row {
  text-align: right;
  padding-right: 8px;
}

.heat__cell {
  display: grid;
  place-items: center;
  min-height: 34px;
  padding: 2px;
  border-radius: 4px;
  background: color-mix(in srgb, var(--accent) calc(var(--v, 0) * 100%), var(--panel-2));
  color: var(--text-strong);
}

.heat__cell.is-masked {
  background: repeating-linear-gradient(135deg, var(--panel-2), var(--panel-2) 4px, transparent 4px, transparent 8px);
  color: var(--text-dim);
}

.heat__cell.is-diverge {
  background: color-mix(in srgb, var(--c-below) calc(max(var(--v, 0), 0) * 100%), color-mix(in srgb, var(--c-real) calc(max(-1 * var(--v, 0), 0) * 100%), var(--panel-2)));
}

.heat__cell.is-current {
  outline: 2px solid var(--c-gold);
  outline-offset: -2px;
}

/* ------------------------------------------------------------ fichas de tokens */
.tokrow {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: var(--space-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel);
  min-height: 44px;
}

.tokchip {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  padding: 2px 6px;
  border-radius: 5px;
  background: color-mix(in srgb, var(--hue) 22%, var(--panel));
  border: 1px solid color-mix(in srgb, var(--hue) 55%, transparent);
  font-family: var(--font-mono);
  font-size: 0.86rem;
  line-height: 1.25;
  color: var(--text-strong);
}

.tokchip small {
  font-size: 0.62rem;
  color: var(--text-muted);
}

.tokchip--bytes {
  background: var(--panel-2);
  border-style: dashed;
  color: var(--text-muted);
}

.tokchip.is-new {
  outline: 2px solid var(--c-gold);
}

.tokchip.is-hit {
  outline: 2px solid var(--accent);
}

.hue-0 { --hue: var(--c-point); }
.hue-1 { --hue: var(--c-above); }
.hue-2 { --hue: var(--c-below); }
.hue-3 { --hue: var(--c-imag); }
.hue-4 { --hue: var(--c-real); }
.hue-5 { --hue: var(--c-region); }
.hue-6 { --hue: var(--c-gold); }

/* ------------------------------------------------------------------ memoria */
.memrow {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
}

.memcell {
  display: grid;
  place-items: center;
  min-width: 26px;
  height: 28px;
  padding: 0 2px;
  border-radius: 3px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-muted);
}

.memcell.is-target {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  font-weight: 700;
}

.memcell.is-path {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--text-strong);
}

.memcell.is-start {
  border-left: 3px solid var(--c-gold);
}

.stack {
  display: flex;
  width: 100%;
  height: 26px;
  border-radius: 6px;
  overflow: hidden;
  background: var(--panel-2);
  border: 1px solid var(--border-strong);
}

.stack__seg {
  flex: 0 0 calc(var(--w, 0) * 100%);
  background: var(--seg, var(--accent));
  min-width: 0;
  transition: flex-basis 0.18s ease;
}

.stack__seg.is-hatch {
  background: repeating-linear-gradient(135deg, var(--seg), var(--seg) 5px, transparent 5px, transparent 10px);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-3);
  font-size: 0.78rem;
  color: var(--text-soft);
}

.legend span::before {
  content: '';
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 6px;
  vertical-align: -1px;
  border-radius: 2px;
  background: var(--swatch, var(--accent));
}

/* ------------------------------------------------------------ pasos y pilas */
.steps {
  display: grid;
  gap: 4px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.steps li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  background: var(--panel);
  border: 1px solid var(--border);
  font-size: 0.82rem;
}

.steps li.is-current {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.steps__n {
  font-family: var(--font-mono);
  color: var(--text-dim);
  min-width: 1.6em;
}

.steps__tag {
  margin-left: auto;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.evt {
  display: grid;
  gap: 2px;
  padding: var(--space-2) var(--space-3);
  border-left: 3px solid var(--border-strong);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: var(--panel);
  font-size: 0.82rem;
}

.evt--action { border-left-color: var(--accent); }
.evt--ok { border-left-color: var(--ok); }
.evt--bad { border-left-color: var(--drop); }
.evt--warn { border-left-color: var(--warn); }

.evt__title {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: baseline;
  color: var(--text-strong);
  font-weight: 600;
}

.evt__body {
  margin: 0;
  color: var(--text-soft);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: var(--font-mono);
  font-size: 0.76rem;
  max-height: 7.5em;
  overflow: hidden;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--space-2);
}

.cardtoggle {
  display: grid;
  gap: 4px;
  padding: var(--space-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text-soft);
  text-align: left;
  cursor: pointer;
  font: inherit;
}

.cardtoggle strong {
  color: var(--text-strong);
}

.cardtoggle small {
  color: var(--text-muted);
  line-height: 1.35;
}

.cardtoggle[aria-pressed='true'] {
  border-color: var(--drop);
  background: var(--drop-soft);
}

.cardtoggle[aria-pressed='false'] {
  border-color: var(--ok);
  background: var(--ok-soft);
}

.cardtoggle:hover {
  filter: brightness(1.08);
}

.codebox {
  margin: 0;
  padding: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--term-bg);
  color: var(--term-fg);
  font-family: var(--font-mono);
  font-size: 0.76rem;
  line-height: 1.5;
  overflow: auto;
  max-height: 260px;
  white-space: pre;
}

.codebox .is-bad {
  background: var(--drop-soft);
  display: inline-block;
  width: 100%;
}

.codebox .is-warn {
  background: var(--warn-soft);
  display: inline-block;
  width: 100%;
}

.timeline {
  display: grid;
  gap: 4px;
}

.timeline__row {
  display: grid;
  grid-template-columns: minmax(70px, 110px) minmax(0, 1fr);
  align-items: center;
  gap: var(--space-2);
  font-size: 0.8rem;
}

.timeline__lane {
  display: flex;
  gap: 2px;
  flex-wrap: wrap;
}

.tcell {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 3px;
  background: var(--panel-2);
  color: var(--text-muted);
  font-size: 0.66rem;
  font-family: var(--font-mono);
}

.tcell.is-ok { background: var(--ok-soft); color: var(--ok); }
.tcell.is-bad { background: var(--drop-soft); color: var(--drop); }
.tcell.is-busy { background: var(--accent); color: var(--on-accent); }
.tcell.is-idle { background: transparent; border: 1px dashed var(--border-strong); }

.blocks {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(10px, 1fr));
  gap: 2px;
}

.blk {
  height: 12px;
  border-radius: 2px;
  background: var(--panel-2);
}

.blk.is-used { background: var(--accent); }
.blk.is-waste { background: var(--drop); opacity: 0.55; }
.blk.is-free { background: var(--panel-2); }
.blk.is-u1 { background: var(--c-point); }
.blk.is-u2 { background: var(--c-above); }
.blk.is-u3 { background: var(--c-below); }
.blk.is-u4 { background: var(--c-imag); }
.blk.is-u5 { background: var(--c-region); }
.blk.is-u6 { background: var(--c-gold); }
