/* Tokens: paleta de referencia validada (dataviz), oscuro por defecto con alternador a claro. */
:root, :root[data-theme="light"] {
  color-scheme: light;
  --page: #f9f9f7; --surface: #fcfcfb; --surface-2: #f1f0ec; --border: rgba(11,11,11,.10);
  --text: #0b0b0b; --text-2: #52514e; --muted: #898781; --grid: #e1e0d9; --axis: #c3c2b7;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s6: #008300; --s7: #4a3aa7; --s8: #e34948;
  --good: #0ca30c; --good-text: #006300; --warn: #fab219; --serious: #ec835a; --bad: #d03b3b;
  --good-bg: rgba(12,163,12,.10); --warn-bg: rgba(250,178,25,.14); --bad-bg: rgba(208,59,59,.10); --accent-bg: rgba(42,120,214,.10);
  --env-demo: #2a78d6; --env-shadow: #898781; --env-live: #d03b3b;
  --radius: 10px; --gap: 14px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232321; --border: rgba(255,255,255,.10);
  --text: #ffffff; --text-2: #c3c2b7; --muted: #898781; --grid: #2c2c2a; --axis: #383835;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --good-text: #0ca30c; --good-bg: rgba(12,163,12,.16); --warn-bg: rgba(250,178,25,.16); --bad-bg: rgba(208,59,59,.18); --accent-bg: rgba(57,135,229,.16);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { background: var(--page); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.muted { color: var(--muted); } .small { font-size: 12px; } .spacer { flex: 1; }
.pos { color: var(--good-text); } .neg { color: var(--bad); }
.num { font-variant-numeric: tabular-nums; }
a { color: var(--s1); }

.shell { display: grid; grid-template-columns: 200px 1fr; grid-template-rows: auto 1fr; min-height: 100vh; }
.topbar { grid-column: 1 / -1; position: sticky; top: 0; z-index: 10; display: flex; gap: 12px; align-items: center; padding: 8px 16px;
  background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.env-badge { font-weight: 800; letter-spacing: .06em; padding: 4px 12px; border-radius: 8px; color: #fff; background: var(--env-demo); font-size: 15px; }
.env-badge.shadow { background: var(--env-shadow); } .env-badge.live { background: var(--env-live); }
.state-pill { padding: 3px 10px; border-radius: 999px; font-weight: 600; font-size: 13px; background: var(--surface-2); border: 1px solid var(--border); }
.state-pill.good { background: var(--good-bg); color: var(--good-text); border-color: transparent; }
.state-pill.warn { background: var(--warn-bg); color: var(--text); border-color: transparent; }
.state-pill.bad { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.top-equity { display: flex; gap: 8px; align-items: baseline; }
.top-equity strong { font-size: 17px; }

.live { display: inline-flex; gap: 6px; align-items: center; }
.live .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--bad); display: inline-block; }
.live.ok .dot { background: var(--good); } .live.slow .dot { background: var(--warn); }
.icon-btn { border: 1px solid var(--border); background: var(--surface-2); color: var(--text); border-radius: 8px; padding: 4px 9px; cursor: pointer; font: inherit; }
select, input[type=search], input[type=date] { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 5px 8px; font: inherit; }
.switch { display: inline-flex; gap: 4px; align-items: center; cursor: pointer; }

.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: 10px 8px; display: flex; flex-direction: column; gap: 2px;
  position: sticky; top: 49px; height: calc(100vh - 49px); }
.sidebar a { display: flex; gap: 10px; align-items: center; color: var(--text-2); text-decoration: none; padding: 8px 10px; border-radius: 8px; }
.sidebar a:hover { background: var(--surface-2); }
.sidebar a.on { background: var(--accent-bg); color: var(--s1); font-weight: 650; }
.sidebar .ico { width: 18px; text-align: center; }
.only-narrow { display: none; }
.view { padding: 16px; min-width: 0; outline: none; }

.grid { display: grid; gap: var(--gap); }
.kpis { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.cols2 { grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); }

.mt { margin-top: var(--gap); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; min-width: 0; }
.card h2 { font-size: 12px; margin: 0 0 10px; color: var(--text-2); font-weight: 650; text-transform: uppercase; letter-spacing: .04em; display: flex; align-items: center; gap: 8px; }
.card h2 .spacer { flex: 1; }
.kpi .l { font-size: 12px; color: var(--muted); }
.kpi .v { font-size: 22px; font-weight: 650; margin: 2px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .s { font-size: 12px; color: var(--text-2); }
.empty { color: var(--muted); padding: 10px 0; }
.chart { width: 100%; }
.h-big { height: 340px; } .h-mid { height: 240px; }

table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; position: sticky; top: 0; background: var(--surface); }
td.r, th.r { text-align: right; }
.scroll { overflow: auto; max-height: 520px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; }
.kv > :nth-child(odd) { color: var(--muted); }
.tag { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); border: 1px solid var(--border); }
.tag.good { background: var(--good-bg); color: var(--good-text); border-color: transparent; }
.tag.warn { background: var(--warn-bg); color: var(--text); border-color: transparent; }
.tag.bad { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.tag.info { background: var(--accent-bg); color: var(--s1); border-color: transparent; }
pre { white-space: pre-wrap; font: 12.5px/1.5 var(--mono); margin: 0; }

/* barra de progreso stop → entrada → objetivo */

/* estados de agentes: color + ícono + texto (nunca solo color) */

@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(12,163,12,.55); } 50% { box-shadow: 0 0 0 6px rgba(12,163,12,0); } }

.events { list-style: none; margin: 0; padding: 0; }
.events li { display: grid; grid-template-columns: 96px 20px 1fr; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--border); align-items: start; }
.sev { width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; font-weight: 800; color: #fff; }
.sev.info { background: var(--s1); } .sev.warning { background: var(--warn); color: #0b0b0b; } .sev.critical { background: var(--bad); }

.drawer { position: fixed; top: 0; right: 0; width: min(560px, 100vw); height: 100vh; background: var(--surface); border-left: 1px solid var(--border);
  z-index: 50; box-shadow: -8px 0 30px rgba(0,0,0,.25); display: flex; flex-direction: column; }
.drawer-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.drawer-body { padding: 14px 16px; overflow: auto; }

.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text-2); }
.legend .sw { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 5px; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; top: 49px; left: 0; z-index: 20; width: 220px; transform: translateX(-100%); transition: transform .2s; box-shadow: 8px 0 24px rgba(0,0,0,.2); }
  .sidebar.open { transform: none; }
  .only-narrow { display: inline-block; }
  .view { padding: 12px; }
  .top-equity strong { font-size: 15px; }
  .cols2{ grid-template-columns: 1fr; }
}

/* ── B4 Agentes ── */

@keyframes spin { to { transform: rotate(360deg); } }

.dh { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-2); margin: 16px 0 6px; }
ul.plain { list-style: none; padding: 0; margin: 0; } ul.plain li { padding: 6px 0; border-bottom: 1px solid var(--border); }
details summary { cursor: pointer; color: var(--s1); margin: 6px 0; }

/* ── B7 Riesgo ── */

.lim { margin-bottom: 14px; }
.lim-head { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 4px; }
.bar { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.bar .fill { display: block; height: 100%; border-radius: 999px; }
.bar .fill.good { background: var(--good); } .bar .fill.warn { background: var(--warn); } .bar .fill.bad { background: var(--bad); }

/* ── B8 Operaciones ── */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.filters label { display: inline-flex; gap: 6px; align-items: center; font-size: 12px; color: var(--muted); }
.scroll.tall { max-height: 560px; }
table.sortable th[data-key] { cursor: pointer; user-select: none; white-space: nowrap; }
table.sortable th[data-key]:hover { color: var(--text); }
tr.row-link { cursor: pointer; }
tr.row-link:hover, tr.row-link:focus-visible { background: var(--surface-2); outline: none; }
.drawer .chart.h-mid { height: 280px; }

/* ── B3 Mercado ── */

#layers { gap: 16px; }

/* ── B5 IA y cuotas ── */

pre.input { max-height: 380px; overflow: auto; background: var(--surface-2); padding: 8px; border-radius: 8px; }
#briefs td:first-child, #briefs td:nth-child(2) { white-space: nowrap; }

/* ── B6 Aprendizaje ── */

.split { display: flex; height: 22px; border-radius: 8px; overflow: hidden; font-size: 11px; font-weight: 650; }
.split span { display: flex; align-items: center; justify-content: center; white-space: nowrap; overflow: hidden; }
 .split .se { background: var(--warn-bg); color: var(--text); }

/* ── B9 Sistema ── */
.svc-grid { display: grid; gap: var(--gap); grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.svc { display: flex; gap: 12px; align-items: center; border-left: 4px solid var(--good); }
.svc .big-ico { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; color: #fff; background: var(--good); flex: none; }
.svc.down { border-left-color: var(--bad); } .svc.down .big-ico { background: var(--bad); }
.svc.opt { border-left-color: var(--axis); } .svc.opt .big-ico { background: var(--muted); }
.news { border-left: 4px solid var(--s1); }
.md p { margin: 6px 0; } .md ul { margin: 4px 0 8px; padding-left: 20px; } .md li { margin: 3px 0; }
.md code, td code { font: 12px var(--mono); background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
