:root {
  --bg: #eef0f2; --surface: #ffffff; --surface-2: #f5f6f8; --line: #dde1e6;
  --text: #15181c; --muted: #5a636e; --accent: #2f5b9a; --on-accent: #fff;
  --ok: #1d7a4a; --ok-bg: #e2f3e9; --warn: #8f5d00; --warn-bg: #fbf0d6; --bad: #b3261e; --bad-bg: #fbe4e2; --gray: #6e7781; --gray-bg: #eceef1;
  /* relleno por tipo (suave) */
  --t-centro: #dbe6f6; --t-agente: #e4ecfb; --t-skill: #efe6fb; --t-herramienta: #e3f1f3; --t-servicio: #f6ebdf; --t-proyecto: #e6f2e2; --t-flujo: #f1efe4;
  --radius: 10px; --mono: ui-monospace, "SF Mono", Menlo, monospace;
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #0f1215; --surface: #171b20; --surface-2: #1e2329; --line: #2b3138;
  --text: #e6e9ed; --muted: #98a2ad; --accent: #82a9e2; --on-accent: #0c1320;
  --ok: #6fd39c; --ok-bg: #13281c; --warn: #e7bc63; --warn-bg: #2b2313; --bad: #f2928b; --bad-bg: #321918; --gray: #8b949e; --gray-bg: #22272d;
  --t-centro: #1e2d44; --t-agente: #1d2638; --t-skill: #2a2138; --t-herramienta: #172c30; --t-servicio: #30261b; --t-proyecto: #1c2b1a; --t-flujo: #2a2919;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif; font-variant-numeric: tabular-nums; }
::selection { background: color-mix(in srgb, var(--accent) 25%, transparent); }
a { color: var(--accent); text-underline-offset: 3px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
h1 { font-size: 1.25rem; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 1rem; margin: 0; }
h3 { font-size: .875rem; margin: .75rem 0 .25rem; }
.sec { margin: .5rem 0 0; font-size: .8125rem; color: var(--muted); font-weight: 600; }
p { margin: .25rem 0; }
.meta { color: var(--muted); font-size: .8125rem; }
.vacio { color: var(--muted); padding: .5rem; margin: 0; }

/* cabecera */
.top { z-index: 20; background: var(--bg); padding: max(.75rem, env(safe-area-inset-top)) 1rem 0; border-bottom: 1px solid var(--line); }
.barra { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; }
.buscador { position: relative; margin-top: .6rem; }
.resultados { position: absolute; inset: calc(100% + 4px) 0 auto; max-height: 60vh; overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 24px rgb(0 0 0 / .16); padding: .25rem; z-index: 30; }
.resultados a, .resultados button { display: block; width: 100%; text-align: left; padding: .55rem .7rem; border-radius: 6px; color: var(--text); text-decoration: none; background: none; border: 0; min-height: 0; font-weight: 400; }
.resultados a:hover, .resultados button:hover { background: var(--surface-2); }
nav { display: flex; gap: .15rem; overflow-x: auto; scrollbar-width: none; margin: .6rem -1rem 0; padding: 0 1rem; }
nav::-webkit-scrollbar { display: none; }
nav a { flex: none; padding: .55rem .7rem; color: var(--muted); text-decoration: none; font-weight: 500; border-bottom: 2px solid transparent; }
nav a:hover { color: var(--text); }
nav a[aria-current] { color: var(--text); border-bottom-color: var(--accent); }

main { padding: .75rem; max-width: 1200px; margin: 0 auto; display: grid; gap: .75rem; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .85rem; min-width: 0; }
.row { display: flex; justify-content: space-between; align-items: center; gap: .6rem; flex-wrap: wrap; }
.row > input[type="search"] { flex: 1; min-width: 12rem; }
.lista { list-style: none; margin: 0; padding: 0; }
.lista li { padding: .45rem 0; border-top: 1px solid var(--line); }
.lista li:first-child { border-top: 0; }
.tarjetas { list-style: none; margin: 0; padding: 0; display: grid; gap: .6rem; }
.tarjetas h3 { margin: 0; }

/* estados: siempre texto + color */
.estado { display: inline-block; font-size: .75rem; font-weight: 600; padding: .05rem .5rem; border-radius: 999px; white-space: nowrap; border: 1px solid transparent; }
.e-conectado.estado, .e-corriendo.estado, .e-ok.estado { color: var(--ok); background: var(--ok-bg); }
.e-pendiente.estado, .e-atención.estado { color: var(--warn); background: var(--warn-bg); }
.e-roto.estado, .e-detenido.estado, .e-fallo.estado { color: var(--bad); background: var(--bad-bg); }
.e-sin-verificar.estado, .e-sin-confirmar.estado, .e-alerta\:-sin-confirmar.estado { color: var(--gray); background: var(--gray-bg); border: 1px dashed var(--gray); }
.falta { display: inline-block; font-size: .75rem; font-weight: 600; color: var(--warn); background: var(--warn-bg); border: 1px dashed currentColor; padding: .05rem .45rem; border-radius: 999px; }
.aviso { background: var(--warn-bg); color: var(--warn); border: 1px solid currentColor; border-radius: 8px; padding: .5rem .65rem; font-size: .875rem; }
.tag { display: inline-block; font-size: .6875rem; font-weight: 600; color: var(--muted); background: var(--surface-2); border: 1px solid var(--line); padding: 0 .35rem; border-radius: 4px; margin-right: .25rem; }

/* controles */
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; min-height: 40px; padding: .45rem .9rem; border-radius: 8px; border: 1px solid var(--accent); background: var(--accent); color: var(--on-accent); font-weight: 600; }
button:hover { filter: brightness(1.08); }
.ghost { display: inline-flex; align-items: center; justify-content: center; min-height: 40px; padding: .45rem .8rem; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font-weight: 500; cursor: pointer; }
.ghost:hover { background: var(--surface-2); filter: none; }
button.link { background: none; border: 0; padding: 0; min-height: 0; color: var(--accent); font-weight: 600; text-align: left; text-decoration: underline; text-underline-offset: 3px; }
input, select, textarea { min-height: 40px; padding: .45rem .65rem; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); width: 100%; }
input::placeholder { color: var(--muted); }
.campo { display: grid; gap: .25rem; font-size: .8125rem; font-weight: 600; color: var(--muted); margin: .4rem 0; }
.campo > * { color: var(--text); font-weight: 400; font-size: .9375rem; }
.form-grid { display: grid; gap: 0 .75rem; }
.boton-archivo input { display: none; }
.chips { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .6rem; }
.chip { min-height: 32px; padding: .2rem .6rem; font-size: .8125rem; font-weight: 500; background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 999px; display: inline-flex; align-items: center; gap: .35rem; }
.chip[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.chip i { width: 10px; height: 10px; border-radius: 3px; border: 2px solid var(--gray); background: var(--surface-2); }
.chip.t-centro i { background: var(--t-centro); } .chip.t-agente i { background: var(--t-agente); border-radius: 50%; } .chip.t-skill i { background: var(--t-skill); transform: rotate(45deg); }
.chip.t-herramienta i { background: var(--t-herramienta); } .chip.t-servicio i { background: var(--t-servicio); } .chip.t-proyecto i { background: var(--t-proyecto); border-radius: 1px; } .chip.t-flujo i { background: var(--t-flujo); width: 16px; border-radius: 6px; }
.chip.e-conectado i, .chip.e-corriendo i { border-color: var(--ok); } .chip.e-pendiente i { border-color: var(--warn); } .chip.e-roto i, .chip.e-detenido i { border-color: var(--bad); } .chip.e-sin-verificar i, .chip.e-sin-confirmar i { border-style: dashed; }

/* mapa */
.mapa-wrap { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; height: min(72vh, 760px); min-height: 420px; }
#svg { width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; user-select: none; -webkit-user-select: none;
  background-image: radial-gradient(var(--line) 1px, transparent 1px); background-size: 22px 22px; }
#svg:active { cursor: grabbing; }
.zoom { position: absolute; top: .5rem; right: .5rem; display: flex; gap: .3rem; }
.zoom .ghost { min-width: 40px; font-size: 1rem; }
.conteo { position: absolute; left: .6rem; bottom: .4rem; margin: 0; }
.nodo { cursor: pointer; }
.nodo > :is(circle, rect, polygon):first-child { stroke-width: 3; stroke: var(--gray); }
.nodo.t-centro > :first-child { fill: var(--t-centro); stroke-width: 4; }
.nodo.t-agente > :first-child { fill: var(--t-agente); } .nodo.t-skill > :first-child { fill: var(--t-skill); } .nodo.t-herramienta > :first-child { fill: var(--t-herramienta); }
.nodo.t-servicio > :first-child { fill: var(--t-servicio); } .nodo.t-proyecto > :first-child { fill: var(--t-proyecto); } .nodo.t-flujo > :first-child { fill: var(--t-flujo); }
.nodo.e-conectado > :first-child, .nodo.e-corriendo > :first-child { stroke: var(--ok); }
.nodo.e-pendiente > :first-child { stroke: var(--warn); }
.nodo.e-roto > :first-child, .nodo.e-detenido > :first-child { stroke: var(--bad); }
.nodo.e-sin-verificar > :first-child, .nodo.e-sin-confirmar > :first-child { stroke-dasharray: 4 3; }
.punto-alerta { fill: var(--surface); stroke: var(--gray); stroke-width: 2; stroke-dasharray: 2 2; }
.nodo text { text-anchor: middle; paint-order: stroke; stroke: var(--surface); stroke-width: 4px; stroke-linejoin: round; }
.lbl { font-size: 13px; font-weight: 600; fill: var(--text); }
.t-centro .lbl { font-size: 18px; }
.lbl-estado { font-size: 10.5px; fill: var(--muted); font-family: var(--mono); }
.nodo:hover > :first-child, .nodo:focus-visible > :first-child, .nodo.sel > :first-child { stroke-width: 5; }
.nodo.sel .lbl { fill: var(--accent); }
.nodo:focus { outline: none; }
.arista line { stroke: var(--line); stroke-width: 1.5; }
[data-theme="dark"] .arista line { stroke: #3a424c; }
.arista.dudosa line { stroke-dasharray: 6 5; stroke: var(--gray); }
.arista.toca line { stroke: var(--accent); stroke-width: 2.5; }
.lbl-arista { font-size: 11px; text-anchor: middle; fill: var(--muted); paint-order: stroke; stroke: var(--surface); stroke-width: 4px; font-family: var(--mono); }
.arista.toca .lbl-arista { fill: var(--text); }
.apagado { opacity: .12; }
.panel { position: absolute; z-index: 5; inset: auto 0 0 0; max-height: 62%; overflow: auto; background: var(--surface); border-top: 1px solid var(--line); box-shadow: 0 -8px 24px rgb(0 0 0 / .12); padding: .85rem; overscroll-behavior: contain; }
.datos { margin: .5rem 0 0; display: grid; gap: .1rem; }
.datos dt { font-size: .75rem; font-weight: 600; color: var(--muted); margin-top: .45rem; }
.datos dd { margin: 0; }
.editor { margin-top: .75rem; border-top: 1px solid var(--line); padding-top: .5rem; }
.editor summary { cursor: pointer; font-weight: 600; min-height: 32px; display: flex; align-items: center; }

/* salud */
.contadores { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: .5rem; }
.cont { display: grid; padding: .6rem .75rem; }
.cont strong { font-size: 1.5rem; line-height: 1.1; font-family: var(--mono); }
.cont span { font-size: .8125rem; color: var(--muted); }
.cont.e-conectado strong { color: var(--ok); } .cont.e-pendiente strong { color: var(--warn); } .cont.e-roto strong { color: var(--bad); } .cont.e-sin-confirmar strong, .cont.e-sin-verificar strong { color: var(--gray); }
.tabla { overflow-x: auto; margin: 0 -.85rem; padding: 0 .85rem; }
table { width: 100%; border-collapse: collapse; font-size: .875rem; min-width: 640px; }
th { text-align: left; font-size: .75rem; color: var(--muted); font-weight: 600; padding: .4rem .6rem .4rem 0; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: .55rem .6rem .55rem 0; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
.nowrap { white-space: nowrap; }

/* flujos: cajas y flechas en CSS */
.flujo { list-style: none; margin: .6rem 0 0; padding: 0; display: flex; flex-direction: column; align-items: flex-start; }
.flujo li { position: relative; padding-bottom: 22px; }
.flujo li:last-child { padding-bottom: 0; }
.flujo li:not(:last-child)::after { content: ""; position: absolute; left: 22px; bottom: 3px; width: 2px; height: 16px; background: var(--muted); }
.flujo li:not(:last-child)::before { content: ""; position: absolute; left: 18px; bottom: 0; border: 5px solid transparent; border-top: 6px solid var(--muted); border-bottom: 0; }
.caja { display: inline-block; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: .45rem .7rem; font-size: .875rem; }
.alternativas { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; }
.o { font-size: .75rem; color: var(--muted); font-weight: 600; }

.pie { max-width: 1200px; margin: 0 auto; padding: .5rem .75rem 2rem; display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.pie .meta { width: 100%; }
.aviso-flotante { position: fixed; left: 50%; bottom: calc(1rem + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--text); color: var(--bg); padding: .55rem 1rem; border-radius: 8px; z-index: 40; max-width: calc(100% - 2rem); }

@media (min-width: 760px) {
  .top { position: sticky; top: 0; padding-inline: 1.25rem; } nav { margin-inline: -1.25rem; padding-inline: 1.25rem; }
  main { padding: 1.25rem; }
  .panel { inset: 0 0 0 auto; width: 360px; max-height: none; border-top: 0; border-left: 1px solid var(--line); box-shadow: -8px 0 24px rgb(0 0 0 / .1); }
  .tarjetas { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid { grid-template-columns: 1fr 1fr; align-items: end; } .form-grid .ancho { grid-column: 1 / -1; }
  .flujo { flex-direction: row; flex-wrap: wrap; align-items: center; row-gap: .5rem; }
  .flujo li { padding: 0 28px 0 0; }
  .flujo li:not(:last-child)::after { left: auto; right: 6px; top: 50%; bottom: auto; width: 16px; height: 2px; }
  .flujo li:not(:last-child)::before { left: auto; right: 0; top: calc(50% - 4px); bottom: auto; border: 5px solid transparent; border-left: 6px solid var(--muted); border-right: 0; }
}
