/* ============================================================================
   jay — dinámica de sistemas · sistema visual
   Tema claro premium. Neutro cálido + índigo de marca; lenguaje semántico
   stock=azul, flujo=slate, aux=verde, coherente con los nodos del lienzo.
   ========================================================================= */

:root {
  /* superficies neutras cálidas (no gris muerto) */
  --bg:          #f4f3ef;
  --bg-well:     #eeece6;
  --surface:     #ffffff;
  --surface-2:   #fbfaf8;
  --canvas-bg:   #fbfcfe;

  /* hairlines cálidas */
  --line:        #e7e4dd;
  --line-strong: #d9d5cc;

  /* tinta */
  --ink:   #1c1e24;
  --ink-2: #3b3e46;
  --muted: #7b7970;

  /* marca índigo (distinta del azul-stock) */
  --brand:       #4f46e5;
  --brand-d:     #4338ca;
  --brand-2:     #6366f1;
  --brand-ghost: rgba(79, 70, 229, .08);
  --focus:       rgba(79, 70, 229, .38);

  /* semánticos (espejan el lienzo) */
  --stock: #3b82f6;
  --flow:  #64748b;
  --aux:   #22c55e;

  --ok:      #15803d;  --ok-bg:  #ecfdf3;  --ok-line:  #bbf7d0;
  --err:     #dc2626;  --err-bg: #fef2f2;  --err-line: #fecaca;

  /* sombras multicapa suaves */
  --sh-sm: 0 1px 2px rgba(24, 24, 27, .05);
  --sh-md: 0 1px 3px rgba(24, 24, 27, .06), 0 6px 16px -6px rgba(24, 24, 27, .10);
  --sh-lg: 0 18px 44px -12px rgba(24, 24, 27, .24), 0 6px 16px -8px rgba(24, 24, 27, .12);

  /* radios */
  --r-xs: 7px;  --r-sm: 9px;  --r: 11px;  --r-lg: 14px;

  --ease: cubic-bezier(.4, 0, .2, 1);
  --dur: 150ms;
}

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

body {
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-feature-settings: "cv02", "cv03", "cv04", "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  color: var(--ink);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* tipografía tabular donde importa el número */
input[type=number], .datatable, .sim .row input { font-variant-numeric: tabular-nums; }

/* etiqueta de sección reutilizable */
.block-eyebrow {
  display: block;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 9px;
}

/* scrollbars finos */
.left, .right, .bot-messages, .tablewrap, .projects-list {
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}
.left::-webkit-scrollbar, .right::-webkit-scrollbar,
.bot-messages::-webkit-scrollbar, .tablewrap::-webkit-scrollbar { width: 9px; height: 9px; }
.left::-webkit-scrollbar-thumb, .right::-webkit-scrollbar-thumb,
.bot-messages::-webkit-scrollbar-thumb, .tablewrap::-webkit-scrollbar-thumb {
  background: var(--line-strong); border-radius: 20px; border: 2px solid transparent; background-clip: content-box;
}

/* ============================================================ topbar */
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 9px 16px;
  background: linear-gradient(var(--surface), var(--surface-2));
  border-bottom: 1px solid var(--line);
  box-shadow: var(--sh-sm);
  flex: 0 0 auto;
  z-index: 5;
}

.brand { display: flex; align-items: center; gap: 11px; flex: 0 0 auto; }
.logo {
  display: inline-grid; place-items: center;
  width: 32px; height: 32px; border-radius: 9px;
  background: linear-gradient(145deg, var(--brand-2), var(--brand-d));
  color: #fff; font-weight: 800; font-size: 19px; line-height: 1;
  box-shadow: 0 2px 6px rgba(67, 56, 202, .35), inset 0 1px 0 rgba(255, 255, 255, .28);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-name { font-weight: 750; font-size: 16px; letter-spacing: -.01em; }
.brand-tag { font-size: 10.5px; color: var(--muted); letter-spacing: .02em; }

.actions { display: flex; align-items: center; gap: 8px; flex: 1 1 auto; flex-wrap: wrap; }
.action-group { display: flex; align-items: center; gap: 6px; }

.actions button, .actions select, .ghostlink {
  font: inherit; font-size: 13px; font-weight: 500;
  padding: 7px 11px; border: 1px solid var(--line);
  background: var(--surface); border-radius: var(--r-xs);
  cursor: pointer; color: var(--ink-2); text-decoration: none;
  box-shadow: var(--sh-sm);
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), color var(--dur) var(--ease);
}
.actions button:hover, .actions select:hover, .ghostlink:hover {
  border-color: var(--line-strong); background: var(--surface-2); color: var(--ink);
}
.actions select { padding-right: 24px; }
.ghostlink { color: var(--muted); box-shadow: none; border-color: transparent; background: transparent; }
.ghostlink:hover { background: var(--brand-ghost); color: var(--brand-d); }

.sep { width: 1px; height: 22px; background: var(--line); flex: 0 0 auto; }

.topbar-right { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }

.bot-toggle {
  font: inherit; font-size: 13px; font-weight: 600;
  padding: 7px 13px; border: 1px solid transparent; border-radius: var(--r-xs);
  cursor: pointer; color: #fff;
  background: linear-gradient(145deg, var(--brand-2), var(--brand-d));
  box-shadow: 0 2px 8px -1px rgba(79, 70, 229, .4), inset 0 1px 0 rgba(255, 255, 255, .22);
  transition: filter var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.bot-toggle:hover { filter: brightness(1.06); }
.bot-toggle:active { transform: translateY(1px); }

/* área de cuenta */
.auth-area { display: flex; align-items: center; }
#btn-login {
  font: inherit; font-size: 13px; font-weight: 600; padding: 7px 13px;
  border: 1px solid var(--line-strong); border-radius: var(--r-xs);
  background: var(--surface); color: var(--ink); cursor: pointer; box-shadow: var(--sh-sm);
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
#btn-login:hover { background: var(--surface-2); border-color: var(--brand); }
.user-info { display: flex; align-items: center; gap: 8px; padding: 3px 4px 3px 3px; border: 1px solid var(--line); border-radius: 20px; background: var(--surface); box-shadow: var(--sh-sm); }
#user-avatar { width: 26px; height: 26px; border-radius: 50%; object-fit: cover; background: var(--bg-well); }
#user-name { font-size: 13px; font-weight: 550; color: var(--ink-2); max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#btn-logout {
  font: inherit; font-size: 14px; line-height: 1; width: 26px; height: 26px;
  display: grid; place-items: center; border: none; border-radius: 50%;
  background: transparent; color: var(--muted); cursor: pointer;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
#btn-logout:hover { background: var(--err-bg); color: var(--err); }

/* ============================================================ layout */
.layout {
  flex: 1 1 auto;
  display: grid; grid-template-columns: 248px 1fr 372px;
  min-height: 0;
}
.left, .right { background: var(--surface); overflow-y: auto; }
.left { border-right: 1px solid var(--line); padding: 16px 14px; display: flex; flex-direction: column; gap: 18px; }
.right { border-left: 1px solid var(--line); display: flex; flex-direction: column; }
.center { position: relative; min-width: 0; background: var(--canvas-bg); }

.panel-block { position: relative; }

/* ============================================================ toolbar */
.toolbar { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tool {
  font: inherit; font-size: 13px; font-weight: 600;
  padding: 13px 8px; border: 1px solid var(--line);
  background: var(--surface); border-radius: var(--r);
  cursor: pointer; text-align: center; color: var(--ink-2);
  box-shadow: var(--sh-sm);
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), color var(--dur) var(--ease), transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.tool:hover { background: var(--surface-2); border-color: var(--line-strong); color: var(--ink); }
.tool:active { transform: translateY(1px); }
.tool.active {
  color: #fff; border-color: transparent;
  background: linear-gradient(145deg, var(--brand-2), var(--brand-d));
  box-shadow: 0 3px 10px -2px rgba(79, 70, 229, .45), inset 0 1px 0 rgba(255, 255, 255, .2);
}

/* ============================================================ tips */
.tips { font-size: 12.5px; color: var(--ink-2); line-height: 1.5; }
.tips ol { margin: 0 0 8px; padding-left: 18px; }
.tips li { margin: 4px 0; }
.tips li b { color: var(--ink); }
.muted { color: var(--muted); }
.tips .muted { display: block; margin-top: 8px; font-size: 11.5px; line-height: 1.45; }

/* ============================================================ sim */
.sim { font-size: 13px; }
.sim .row { display: flex; align-items: center; gap: 9px; margin-top: 8px; }
.sim .row label { width: 52px; color: var(--muted); font-size: 12px; }
.sim .row input, .sim .row select {
  flex: 1; font: inherit; font-size: 13px; padding: 6px 9px;
  border: 1px solid var(--line); border-radius: var(--r-sm); min-width: 0;
  background: var(--surface-2); color: var(--ink);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), background var(--dur) var(--ease);
}
.sim .row input:focus, .sim .row select:focus {
  outline: none; border-color: var(--brand); background: var(--surface);
  box-shadow: 0 0 0 3px var(--focus);
}
.sim .btns { flex-wrap: wrap; margin-top: 12px; gap: 7px; }
.sim .btns button {
  font: inherit; font-size: 13px; font-weight: 550; padding: 8px 11px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-2);
  border-radius: var(--r-sm); cursor: pointer; box-shadow: var(--sh-sm);
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.sim .btns button:hover { background: var(--surface-2); border-color: var(--line-strong); }
.sim .btns button:active { transform: translateY(1px); }
.sim .btns button:disabled { opacity: .4; cursor: default; transform: none; }
#btn-undo, #btn-redo { font-size: 16px; line-height: 1; padding: 8px 12px; }

button.primary {
  background: linear-gradient(145deg, var(--brand-2), var(--brand-d)) !important;
  color: #fff !important; border-color: transparent !important; font-weight: 650 !important;
  box-shadow: 0 3px 10px -2px rgba(79, 70, 229, .45), inset 0 1px 0 rgba(255, 255, 255, .2) !important;
}
button.primary:hover { filter: brightness(1.06); }

/* ============================================================ proyectos */
.projects { border-top: 1px dashed var(--line); padding-top: 16px; margin-top: 2px; }
.btn-save {
  width: 100%; font: inherit; font-size: 13px; font-weight: 600; padding: 9px;
  border: 1px solid var(--brand); border-radius: var(--r-sm); cursor: pointer;
  color: var(--brand-d); background: var(--brand-ghost);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.btn-save:hover { background: var(--brand); color: #fff; }
.projects-list { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 5px; max-height: 220px; overflow-y: auto; }
.project-item {
  display: flex; align-items: center; gap: 6px;
  font-size: 12.5px; padding: 7px 9px;
  border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--surface-2);
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.project-item:hover { border-color: var(--line-strong); background: var(--surface); }
.project-item > span, .project-item .project-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); font-weight: 550; }
.project-open, .project-del {
  font: inherit; font-size: 12px; padding: 3px 8px; border-radius: var(--r-xs); cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-2);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.project-open:hover { border-color: var(--brand); color: var(--brand-d); background: var(--brand-ghost); }
.project-del:hover { border-color: var(--err-line); color: var(--err); background: var(--err-bg); }

/* ============================================================ canvas */
.canvas { width: 100%; height: 100%; display: block; background: var(--canvas-bg); user-select: none; }
.canvas .bg { fill: url(#dotgrid); }
.node { cursor: pointer; }
.node rect, .node circle { transition: filter var(--dur) var(--ease); }
.node:hover rect, .node:hover circle { filter: drop-shadow(0 3px 6px rgba(24, 24, 27, .16)); }
.nodelabel { font-size: 12px; fill: var(--ink); pointer-events: none; font-weight: 650; letter-spacing: -.005em; }
.valve .nodelabel { font-weight: 500; fill: var(--flow); }
.pipe { fill: none; stroke: #94a3b8; stroke-width: 7; stroke-linejoin: round; stroke-linecap: round; }
.infolink { fill: none; stroke: #cbd5e1; stroke-width: 1.5; }
.cloud { fill: #fff; stroke: #cbd5e1; stroke-width: 1.5; }
.draft { stroke: var(--brand); stroke-width: 2; stroke-dasharray: 5 4; }

/* hint discreto y permanente en el lienzo */
.canvas-hint {
  position: absolute; top: 14px; right: 16px;
  font-size: 11.5px; color: var(--muted);
  padding: 5px 11px; border-radius: 20px;
  background: rgba(255, 255, 255, .72); border: 1px solid var(--line);
  backdrop-filter: saturate(1.4) blur(4px);
  pointer-events: none; opacity: .8;
}

/* estado de la app */
.status {
  position: absolute; left: 14px; bottom: 14px;
  font-size: 12.5px; font-weight: 550; padding: 7px 14px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 20px; box-shadow: var(--sh-md); color: var(--ink-2);
}
.status.ok  { color: var(--ok);  border-color: var(--ok-line);  background: var(--ok-bg); }
.status.err { color: var(--err); border-color: var(--err-line); background: var(--err-bg); }

/* ============================================================ panel derecho */
.eq-panel { padding: 16px 15px; border-bottom: 1px solid var(--line); }
.eq-panel input[type=text], .eq-panel textarea,
#eq-body input, #eq-body textarea {
  width: 100%; font: inherit; font-size: 13px; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: var(--r-sm);
  background: var(--surface-2); color: var(--ink);
  font-family: ui-monospace, "SFMono-Regular", "SF Mono", Menlo, Consolas, monospace;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), background var(--dur) var(--ease);
}
#eq-body input:focus, #eq-body textarea:focus {
  outline: none; border-color: var(--brand); background: var(--surface);
  box-shadow: 0 0 0 3px var(--focus);
}
#eq-body textarea { resize: vertical; line-height: 1.5; }
#eq-body label { display: block; font-size: 11.5px; color: var(--muted); margin: 12px 0 4px; font-weight: 550; }

.eq-head { margin-bottom: 6px; }
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 10.5px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  padding: 3px 10px; border-radius: 20px; color: #fff;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .22);
}
.badge.stock { background: var(--stock); }
.badge.flow  { background: var(--flow); }
.badge.aux   { background: var(--aux); }

.chk {
  display: flex !important; align-items: center; gap: 8px;
  margin-top: 12px !important; color: var(--ink-2) !important;
  font-size: 12.5px; cursor: pointer;
}
.chk input { width: auto !important; accent-color: var(--brand); }
.eq-error { color: var(--err); font-size: 12px; margin-top: 8px; min-height: 0; line-height: 1.4; }
.eq-error.show {
  min-height: 16px; padding: 7px 10px; border-radius: var(--r-sm);
  background: var(--err-bg); border: 1px solid var(--err-line);
}
button.danger {
  margin-top: 14px; width: 100%; font: inherit; font-size: 13px; font-weight: 550; padding: 9px;
  cursor: pointer; background: var(--surface); color: var(--err);
  border: 1px solid var(--err-line); border-radius: var(--r-sm);
  transition: background var(--dur) var(--ease);
}
button.danger:hover { background: var(--err-bg); }
.hint { margin-top: 12px; font-size: 11px; color: var(--muted); line-height: 1.5; }

/* resultados */
.results { padding: 16px 15px; flex: 1; min-height: 0; display: flex; flex-direction: column; }
.chart {
  width: 100%; height: 224px; flex: 0 0 auto;
  border: 1px solid var(--line); border-radius: var(--r); background: var(--surface-2);
  padding: 4px;
}
.legend { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.legitem {
  font: inherit; font-size: 12px; font-weight: 550; padding: 4px 10px;
  border: 1px solid var(--line); background: var(--surface); border-radius: 20px;
  cursor: pointer; display: inline-flex; align-items: center; gap: 7px; opacity: .5;
  transition: opacity var(--dur) var(--ease), border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.legitem:hover { border-color: var(--line-strong); background: var(--surface-2); }
.legitem.on { opacity: 1; }
.swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .06); }

.tablewrap { overflow: auto; flex: 1; min-height: 60px; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); }
.datatable { border-collapse: collapse; width: 100%; font-size: 12px; }
.datatable th, .datatable td { border-bottom: 1px solid var(--line); padding: 5px 10px; text-align: right; white-space: nowrap; }
.datatable tbody tr:nth-child(even) { background: var(--surface-2); }
.datatable tbody tr:hover { background: var(--brand-ghost); }
.datatable th {
  position: sticky; top: 0; z-index: 1;
  background: var(--bg-well); color: var(--muted);
  font-weight: 650; letter-spacing: .02em;
  box-shadow: inset 0 -1px 0 var(--line-strong);
}
.datatable td:first-child, .datatable th:first-child { text-align: left; color: var(--muted); font-variant-numeric: tabular-nums; }
/* fila activa del scrubber */
.datatable tbody tr.active-row, .datatable tbody tr.active-row:hover { background: var(--brand-ghost); box-shadow: inset 2px 0 0 var(--brand); }
.datatable tbody tr.active-row td:first-child { color: var(--brand-d); font-weight: 700; }

/* cabecera del panel de resultados + botón expandir */
.results-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.results-head .block-eyebrow { margin-bottom: 0; }
.chart-expand {
  font: inherit; font-size: 15px; line-height: 1; width: 30px; height: 26px;
  display: grid; place-items: center; cursor: pointer;
  border: 1px solid var(--line); border-radius: var(--r-xs);
  background: var(--surface); color: var(--muted); box-shadow: var(--sh-sm);
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.chart-expand:hover { background: var(--surface-2); border-color: var(--line-strong); color: var(--ink); }
.chart-expand.active {
  color: #fff; border-color: transparent;
  background: linear-gradient(145deg, var(--brand-2), var(--brand-d));
  box-shadow: 0 2px 8px -2px rgba(79, 70, 229, .45), inset 0 1px 0 rgba(255, 255, 255, .2);
}

/* ============================================================ comparar corridas (toggle) */
.cmp-toggle {
  display: flex; align-items: center; gap: 8px; margin-top: 12px;
  font-size: 12.5px; color: var(--ink-2); cursor: pointer; user-select: none;
}
.cmp-toggle input { width: auto; accent-color: var(--brand); cursor: pointer; }
.cmp-count {
  margin-left: auto; font-size: 11px; font-weight: 700; font-variant-numeric: tabular-nums;
  min-width: 20px; height: 20px; padding: 0 6px; display: inline-grid; place-items: center;
  border-radius: 20px; color: #fff; background: var(--brand);
}

/* ============================================================ pestañas Series ⇄ Fase */
.results-tabs { display: flex; gap: 2px; margin: 0 auto 0 6px; padding: 2px; border-radius: var(--r-xs); background: var(--bg-well); }
.rtab {
  font: inherit; font-size: 12px; font-weight: 600; padding: 4px 12px;
  border: none; border-radius: var(--r-xs); cursor: pointer;
  background: transparent; color: var(--muted);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.rtab:hover { color: var(--ink-2); }
.rtab.active { background: var(--surface); color: var(--brand-d); box-shadow: var(--sh-sm); }

/* selectores de eje del retrato de fase */
.phase-axes { display: flex; gap: 12px; margin: 10px 0 2px; }
.phase-axes label { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); font-weight: 550; }
.phase-axes select {
  font: inherit; font-size: 12.5px; padding: 5px 8px; border: 1px solid var(--line);
  border-radius: var(--r-sm); background: var(--surface-2); color: var(--ink); cursor: pointer;
  max-width: 130px;
}
.phase-axes select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--focus); }

/* ============================================================ panel de corridas */
.runs-panel { display: flex; flex-direction: column; gap: 5px; margin: 4px 0 10px; }
.runs-empty { font-size: 12.5px; color: var(--muted); padding: 10px 4px; text-align: center; }
.run-item {
  display: flex; align-items: center; gap: 7px;
  font-size: 12px; padding: 5px 8px;
  border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--surface-2);
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease), opacity var(--dur) var(--ease);
}
.run-item:hover { border-color: var(--line-strong); background: var(--surface); }
.run-item.hidden-run { opacity: .5; }
.run-item.baseline { border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand-ghost); }
.run-item.obsolete { border-color: var(--err-line); background: var(--err-bg); }
.run-swatch { flex: 0 0 auto; width: 14px; height: 3px; border-radius: 2px; }
.run-name {
  flex: 1; min-width: 0; font: inherit; font-size: 12px; font-weight: 550; color: var(--ink-2);
  border: 1px solid transparent; border-radius: var(--r-xs); background: transparent; padding: 3px 5px;
  overflow: hidden; text-overflow: ellipsis;
}
.run-name:focus { outline: none; border-color: var(--brand); background: var(--surface); box-shadow: 0 0 0 2px var(--focus); }
.run-obsolete-tag { flex: 0 0 auto; font-size: 9.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--err); }
.run-btn {
  flex: 0 0 auto; font: inherit; font-size: 12px; line-height: 1; width: 24px; height: 22px;
  display: grid; place-items: center; cursor: pointer;
  border: 1px solid transparent; border-radius: var(--r-xs);
  background: transparent; color: var(--muted);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.run-btn:hover { background: var(--bg-well); color: var(--ink); border-color: var(--line); }
.run-btn.on { color: var(--brand-d); }
.run-btn.pin.on { color: var(--brand); }
.run-btn.base.on { color: var(--brand-d); background: var(--brand-ghost); }
.run-btn.del:hover { color: var(--err); background: var(--err-bg); border-color: var(--err-line); }

/* aviso de obsolescencia */
.runs-obsolete {
  display: flex; align-items: center; gap: 10px; margin: 8px 0 2px;
  font-size: 12px; padding: 8px 11px; border-radius: var(--r-sm);
  background: var(--err-bg); border: 1px solid var(--err-line); color: var(--err);
}
.runs-obsolete span { flex: 1; }
.runs-obsolete button {
  font: inherit; font-size: 12px; font-weight: 600; padding: 5px 10px; cursor: pointer;
  border: 1px solid var(--err-line); border-radius: var(--r-xs); background: var(--surface); color: var(--err);
}
.runs-obsolete button:hover { background: var(--err); color: #fff; }

/* ============================================================ player de simulación */
.player {
  display: flex; align-items: center; gap: 8px; margin: 12px 0 8px;
  padding: 7px 9px; border: 1px solid var(--line); border-radius: var(--r);
  background: var(--surface-2);
}
.player-btn {
  flex: 0 0 auto; font: inherit; font-size: 14px; line-height: 1;
  width: 32px; height: 32px; display: grid; place-items: center; cursor: pointer;
  border: 1px solid transparent; border-radius: 50%; color: #fff;
  background: linear-gradient(145deg, var(--brand-2), var(--brand-d));
  box-shadow: 0 2px 8px -2px rgba(79, 70, 229, .4), inset 0 1px 0 rgba(255, 255, 255, .2);
  transition: filter var(--dur) var(--ease), transform var(--dur) var(--ease), opacity var(--dur) var(--ease);
}
.player-btn:hover:not(:disabled) { filter: brightness(1.06); }
.player-btn:active:not(:disabled) { transform: translateY(1px); }
.player-btn:disabled { opacity: .4; cursor: default; background: var(--muted); box-shadow: none; }

.player-scrub {
  flex: 1 1 auto; min-width: 0; height: 4px; margin: 0; cursor: pointer;
  -webkit-appearance: none; appearance: none; background: transparent;
}
.player-scrub::-webkit-slider-runnable-track { height: 4px; border-radius: 3px; background: var(--line-strong); }
.player-scrub::-moz-range-track { height: 4px; border-radius: 3px; background: var(--line-strong); }
.player-scrub::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; margin-top: -5px;
  width: 14px; height: 14px; border-radius: 50%; cursor: pointer;
  background: var(--brand); border: 2px solid var(--surface); box-shadow: var(--sh-sm);
}
.player-scrub::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%; cursor: pointer;
  background: var(--brand); border: 2px solid var(--surface); box-shadow: var(--sh-sm);
}
.player-scrub:focus-visible { outline: none; }
.player-scrub:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 3px var(--focus); }
.player-scrub:disabled { opacity: .5; cursor: default; }
.player-scrub:disabled::-webkit-slider-thumb { background: var(--muted); cursor: default; }
.player-scrub:disabled::-moz-range-thumb { background: var(--muted); cursor: default; }

.player-speed {
  flex: 0 0 auto; font: inherit; font-size: 12px; padding: 5px 6px;
  border: 1px solid var(--line); border-radius: var(--r-xs);
  background: var(--surface); color: var(--ink-2); cursor: pointer;
}
.player-speed:disabled { opacity: .5; cursor: default; }
.player-time {
  flex: 0 0 auto; font-size: 12px; font-weight: 600; color: var(--ink-2);
  font-variant-numeric: tabular-nums; min-width: 62px; text-align: right;
}

.player-readout { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.ro-item {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11.5px; padding: 3px 9px; border-radius: 20px;
  border: 1px solid var(--line); background: var(--surface);
}
.ro-dot { width: 8px; height: 8px; border-radius: 3px; display: inline-block; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .06); }
.ro-name { color: var(--muted); font-weight: 550; }
.ro-val { color: var(--ink); font-weight: 650; font-variant-numeric: tabular-nums; }

/* ============================================================ modo expandido */
.layout { transition: grid-template-columns var(--dur) var(--ease); }
.layout.results-wide { grid-template-columns: 248px 1fr 560px; }
.chart { transition: height var(--dur) var(--ease); }
.layout.results-wide .chart { height: 380px; }

/* íconos SVG inline en botones-herramienta (el markup lo inyecta otro módulo) */
.tool svg { width: 20px; height: 20px; stroke: currentColor; fill: none; display: block; }
.tool.has-icon { display: flex; flex-direction: column; align-items: center; gap: 5px; }

/* ============================================================ drawer del asistente */
.bot-panel {
  position: fixed; right: 20px; bottom: 20px; z-index: 40;
  width: 380px; max-height: 70vh;
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); box-shadow: var(--sh-lg);
  overflow: hidden;
  transform-origin: bottom right;
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.bot-panel.closed {
  opacity: 0; transform: translateY(12px) scale(.97);
  pointer-events: none; visibility: hidden;
}
.bot-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 13px 15px; border-bottom: 1px solid var(--line);
  background: linear-gradient(var(--surface), var(--surface-2));
}
.bot-title { font-size: 13.5px; font-weight: 700; display: flex; align-items: center; gap: 8px; letter-spacing: -.01em; }
.bot-spark { font-size: 14px; }
.bot-close {
  font: inherit; font-size: 13px; line-height: 1; width: 28px; height: 28px;
  display: grid; place-items: center; border: none; border-radius: var(--r-xs);
  background: transparent; color: var(--muted); cursor: pointer;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.bot-close:hover { background: var(--bg-well); color: var(--ink); }

.bot-messages {
  flex: 1 1 auto; min-height: 120px; overflow-y: auto;
  padding: 15px; display: flex; flex-direction: column; gap: 11px;
  background: var(--bg);
}
.bot-msg {
  max-width: 86%; font-size: 13px; line-height: 1.5;
  padding: 9px 13px; border-radius: 14px; white-space: pre-wrap; word-wrap: break-word;
  box-shadow: var(--sh-sm);
}
.bot-msg.user {
  align-self: flex-end; color: #fff;
  background: linear-gradient(145deg, var(--brand-2), var(--brand-d));
  border-bottom-right-radius: 5px;
}
.bot-msg.ai {
  align-self: flex-start; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line);
  border-bottom-left-radius: 5px;
}
.bot-msg.error {
  align-self: flex-start; color: var(--err);
  background: var(--err-bg); border: 1px solid var(--err-line);
  border-bottom-left-radius: 5px;
}
.bot-msg.thinking {
  align-self: flex-start; color: var(--muted);
  background: var(--surface); border: 1px solid var(--line);
  border-bottom-left-radius: 5px;
  animation: bot-pulse 1.3s var(--ease) infinite;
}
@keyframes bot-pulse { 0%, 100% { opacity: .55; } 50% { opacity: 1; } }

.bot-form {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 11px; border-top: 1px solid var(--line); background: var(--surface);
}
#bot-input {
  flex: 1; font: inherit; font-size: 13px; line-height: 1.45; resize: none;
  padding: 9px 11px; border: 1px solid var(--line); border-radius: var(--r-sm);
  background: var(--surface-2); color: var(--ink); max-height: 120px;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), background var(--dur) var(--ease);
}
#bot-input:focus { outline: none; border-color: var(--brand); background: var(--surface); box-shadow: 0 0 0 3px var(--focus); }
.bot-send {
  flex: 0 0 auto; width: 38px; height: 38px; font-size: 17px; line-height: 1;
  display: grid; place-items: center; border: none; border-radius: var(--r-sm); cursor: pointer;
  color: #fff; background: linear-gradient(145deg, var(--brand-2), var(--brand-d));
  box-shadow: 0 2px 8px -1px rgba(79, 70, 229, .4), inset 0 1px 0 rgba(255, 255, 255, .2);
  transition: filter var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.bot-send:hover { filter: brightness(1.06); }
.bot-send:active { transform: translateY(1px); }
.bot-send:disabled { opacity: .45; cursor: default; }

/* ============================================================ accesibilidad */
:where(button, a, input, select, textarea):focus-visible {
  outline: 2px solid var(--brand); outline-offset: 2px; border-radius: var(--r-xs);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}

/* ============================================================ responsive */
@media (max-width: 1024px) {
  .layout, .layout.results-wide { grid-template-columns: 1fr; grid-template-rows: auto 1fr auto; overflow: auto; }
  .left { flex-direction: row; flex-wrap: wrap; align-items: flex-start; }
  .left > .panel-block { flex: 1 1 200px; }
  .center { height: 58vh; min-height: 340px; }
  .right { max-height: 62vh; }
  .bot-panel { left: 12px; right: 12px; bottom: 12px; width: auto; max-height: 76vh; }
  .topbar { flex-wrap: wrap; }
  .actions { order: 3; flex-basis: 100%; }
}

/* ============================================================ sugerencias del bot */
.bot-suggestions { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.bot-suggestion {
  font: inherit; font-size: 12.5px; text-align: left;
  padding: 7px 11px; border: 1px solid var(--line); border-radius: var(--r-sm);
  background: var(--surface); color: var(--ink-2); cursor: pointer;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.bot-suggestion:hover { background: var(--brand-ghost); border-color: var(--brand-2); color: var(--brand-d); }

/* hidden SIEMPRE gana (nuestro display:flex en .user-info/.projects lo pisaba) */
[hidden] { display: none !important; }

/* ============================================================ aparición de nodos (bot) */
@keyframes jay-appear {
  from { opacity: 0; transform: scale(.85); }
  to   { opacity: 1; transform: scale(1); }
}
#canvas g.node.appear { animation: jay-appear 260ms var(--ease) both; transform-box: fill-box; transform-origin: center; }
@media (prefers-reduced-motion: reduce) { #canvas g.node.appear { animation: none; } }

/* botón cancelar del "Pensando…" */
.bot-cancel {
  font: inherit; font-size: 12px; line-height: 1; margin-left: 8px;
  width: 20px; height: 20px; border: 1px solid var(--line); border-radius: 50%;
  background: var(--surface); color: var(--muted); cursor: pointer;
}
.bot-cancel:hover { background: var(--err-bg); color: var(--err); border-color: var(--err-line); }

/* ============================================================ menú contextual */
.ctx-menu {
  position: fixed; z-index: 60; min-width: 200px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r); box-shadow: var(--sh-lg);
  padding: 5px; display: flex; flex-direction: column;
}
.ctx-item {
  font: inherit; font-size: 13px; text-align: left;
  padding: 8px 12px; border: none; border-radius: var(--r-xs);
  background: transparent; color: var(--ink-2); cursor: pointer;
}
.ctx-item:hover { background: var(--brand-ghost); color: var(--brand-d); }
.ctx-item.danger { color: var(--err); }
.ctx-item.danger:hover { background: var(--err-bg); color: var(--err); }
