:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --ink: #1d2433;
  --muted: #6b7385;
  --line: #e3e6ec;
  --brand: #2f5bea;
  --brand-ink: #ffffff;
  --brand-soft: #eaf0ff;
  --ok: #157a4a;
  --ok-soft: #e4f5ec;
  --warn: #9a6200;
  --warn-soft: #fff4dc;
  --bad: #b42318;
  --bad-soft: #fdecea;
  --radius: 10px;
  --side: 232px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 18px 0 10px; }
h3 .muted { font-weight: 400; font-size: 12.5px; }
td .small { font-size: 12.5px; margin-top: 2px; }
p { margin: 0 0 10px; }
code, pre { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12.5px; }
pre { background: #10172a; color: #dbe4ff; padding: 14px; border-radius: 8px; overflow-x: auto; white-space: pre-wrap; word-break: break-all; }

/* Estructura */
.layout { display: flex; min-height: 100vh; }
.side {
  width: var(--side); flex: 0 0 var(--side); background: #141b2d; color: #c9d1e4;
  padding: 18px 12px; display: flex; flex-direction: column; gap: 4px;
}
.brand { color: #fff; font-weight: 700; font-size: 17px; padding: 4px 10px 14px; letter-spacing: .2px; }
.brand span { color: #8fb0ff; }
.side a { color: #c9d1e4; padding: 8px 10px; border-radius: 8px; display: block; }
.side a:hover { background: #1f2840; text-decoration: none; }
.side a.on { background: var(--brand); color: #fff; }
.side .grow { flex: 1; }
.side select { width: 100%; padding: 7px; border-radius: 8px; border: 0; margin-bottom: 10px; background: #fff; color: var(--ink); }
.side .small { font-size: 12px; color: #8a93ab; padding: 0 10px; }
.side button.link { background: none; border: 0; color: #c9d1e4; padding: 8px 10px; cursor: pointer; font: inherit; text-align: left; width: 100%; border-radius: 8px; }
.side button.link:hover { background: #1f2840; }
.main { flex: 1; min-width: 0; padding: 26px 30px 60px; }
.head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.head .sub { color: var(--muted); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Tarjetas */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 18px; }
.grid { display: grid; gap: 14px; }
.grid.k4 { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.grid.c2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid.c4 { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.grid.k6 { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; }
.chart .bar { fill: var(--brand); }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover { fill: rgba(47, 91, 234, .07); }
.chart .grid-line { stroke: var(--line); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .axis-line { stroke: #c9ced8; stroke-width: 1; }
.chart .axis-label { fill: var(--muted); font-size: 11px; }
.chart-tip { position: absolute; pointer-events: none; background: var(--ink); color: #fff; font-size: 12px; padding: 4px 8px; border-radius: 6px; white-space: nowrap; transform: translate(-50%, -100%); }
.chart-empty { position: absolute; inset: 0 0 24px 52px; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 13px; pointer-events: none; }
.blocks-layout { align-items: start; }
.blk { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-bottom: 10px; background: #fbfbfd; }
.blk-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.blk-tools { display: flex; gap: 4px; }
.blk-fields { display: grid; gap: 8px; }
.blk-field { display: grid; gap: 3px; font-size: 13px; color: var(--muted); }
.blk-field textarea { min-height: 90px; }
.blocks-add { display: flex; flex-wrap: wrap; gap: 6px; }
.blocks-preview { width: 100%; height: 720px; border: 1px solid var(--line); border-radius: 8px; background: #f3f4f6; }
.ab-box { margin: 0 0 14px; padding: 10px 14px; border: 1px dashed var(--line); border-radius: 8px; }
.ab-box > summary { cursor: pointer; color: var(--brand); }
.ab-box[open] > summary { margin-bottom: 10px; }
details.card > summary { cursor: pointer; color: var(--brand); }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.kpi .n { font-size: 26px; font-weight: 700; }
.kpi .l { color: var(--muted); font-size: 13px; }

/* Tablas */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; }
.num { text-align: right; white-space: nowrap; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }

/* Etiquetas */
.tag { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; background: #eef0f4; color: #4a5368; }
.tag.ok, .tag.active, .tag.completed, .tag.sent { background: var(--ok-soft); color: var(--ok); }
.tag.warn, .tag.paused, .tag.waiting, .tag.queued { background: var(--warn-soft); color: var(--warn); }
.tag.bad, .tag.failed { background: var(--bad-soft); color: var(--bad); }
.tag.draft, .tag.exited { background: #eef0f4; color: #4a5368; }

/* Formularios */
label { display: block; font-weight: 600; margin: 0 0 5px; font-size: 13px; }
.field { margin-bottom: 14px; }
.hint { color: var(--muted); font-size: 12.5px; font-weight: 400; margin-top: 4px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=search], input[type=datetime-local], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid #cfd4de; border-radius: 8px; background: #fff; font: inherit; color: inherit;
}
textarea { min-height: 180px; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 13px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
.check { display: flex; gap: 8px; align-items: center; font-weight: 400; }
.check input { width: auto; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > * { flex: 1 1 140px; }
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn:hover { text-decoration: none; border-color: #c4cad6; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { background: #2549c4; }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.inline { display: inline; }

/* Avisos */
.alert { padding: 11px 14px; border-radius: 8px; margin-bottom: 16px; }
.alert.ok { background: var(--ok-soft); color: var(--ok); }
.alert.error { background: var(--bad-soft); color: var(--bad); }
.alert ul { margin: 0; padding-left: 18px; }

/* Constructor de reglas y pasos */
.rule, .step { border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin-bottom: 10px; background: #fafbfc; }
.step-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; gap: 10px; }
.step-num { display: inline-flex; width: 26px; height: 26px; border-radius: 50%; background: var(--brand); color: #fff; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; }
.step[data-type=wait] .step-num { background: #7c5cff; }
.step[data-type=condition] .step-num { background: #d97706; }
.step-arrow { text-align: center; color: var(--muted); margin: -4px 0 6px; }
.vars code { background: var(--brand-soft); color: #23419e; padding: 1px 6px; border-radius: 5px; margin: 0 4px 4px 0; display: inline-block; }
.count-badge { font-size: 22px; font-weight: 700; }
.timeline li { margin-bottom: 8px; }
.timeline { padding-left: 18px; margin: 0; }
.pager { margin-top: 14px; }
.pager .pagination { list-style: none; display: flex; gap: 8px; padding: 0; margin: 0; }
.pager .pagination li > * { display: inline-block; padding: 6px 12px; border: 1px solid var(--line); border-radius: 8px; }
.pager .pagination li.disabled { color: var(--muted); }
.templates { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; }
.templates a { display: block; border: 1px solid var(--line); border-radius: 10px; padding: 14px; background: #fff; color: var(--ink); }
.templates a:hover { border-color: var(--brand); text-decoration: none; }
.templates strong { display: block; margin-bottom: 4px; }

/* Editor visual de workflows */
.flow-scroll { overflow-x: auto; padding: 8px 0 16px; }
.flow { display: flex; flex-direction: column; align-items: center; min-width: min-content; }
.flow .fnode {
  position: relative; width: 240px; background: #fff; border: 1px solid var(--line); border-left: 4px solid var(--brand);
  border-radius: 10px; padding: 10px 30px 10px 12px; box-shadow: 0 1px 2px rgba(0,0,0,.04);
}
.flow .fnode[role=button] { cursor: pointer; }
.flow .fnode[role=button]:hover, .flow .fnode[role=button]:focus { border-color: #b8c4e8; outline: 2px solid var(--brand-soft); }
.flow .fnode.trigger { border-left-color: #141b2d; background: #f2f4f8; }
.flow .fnode.wait { border-left-color: #7c5cff; }
.flow .fnode.condition { border-left-color: #d97706; }
.flow .fnode.email { border-left-color: #157a4a; }
.flow .fnode.wait_until { border-left-color: #7c5cff; }
.flow .fnode.split { border-left-color: #db2777; }
.flow .fnode.tag { border-left-color: #0891b2; }
.flow .fnode.webhook { border-left-color: #475569; }
.flow .fstats { margin-top: 6px; font-size: 12px; color: var(--muted); }
dialog .days { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.flow .fkind { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 700; }
.flow .ftitle { font-weight: 600; margin-top: 2px; overflow-wrap: anywhere; }
.flow .fcount { margin-top: 6px; font-size: 12px; font-weight: 700; color: var(--warn); }
.flow .fdel { position: absolute; top: 6px; right: 6px; border: 0; background: none; color: var(--muted); font-size: 18px; line-height: 1; cursor: pointer; padding: 2px 4px; }
.flow .fdel:hover { color: var(--bad); }
.flow .fline { width: 2px; height: 22px; background: #c9cfdb; }
.flow .fadd { position: relative; display: flex; flex-direction: column; align-items: center; }
.flow .fadd::before, .flow .fadd::after { content: ''; width: 2px; height: 10px; background: #c9cfdb; }
.flow .fplus {
  width: 24px; height: 24px; border-radius: 50%; border: 1px solid #c9cfdb; background: #fff; color: var(--brand);
  font-weight: 700; line-height: 1; cursor: pointer;
}
.flow .fplus:hover { background: var(--brand); color: #fff; border-color: var(--brand); }
.flow .fmenu {
  position: absolute; top: 34px; z-index: 5; background: #fff; border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.12); padding: 4px; display: flex; flex-direction: column; min-width: 190px;
}
.flow .fmenu[hidden] { display: none; }
.flow .fmenu button { border: 0; background: none; text-align: left; padding: 8px 10px; border-radius: 6px; cursor: pointer; font: inherit; }
.flow .fmenu button:hover { background: var(--brand-soft); }
.flow .fbranches { display: flex; gap: 24px; align-items: flex-start; margin-top: 12px; padding-top: 12px; border-top: 2px solid #c9cfdb; }
.flow .fbranch { flex: 1 1 auto; display: flex; flex-direction: column; align-items: center; min-width: 260px; }
.flow .fbranch.empty { flex: 0 0 auto; min-width: 150px; }
.flow .fblabel { font-size: 12px; font-weight: 700; padding: 2px 10px; border-radius: 99px; background: var(--ok-soft); color: var(--ok); }
.flow .fbranch.no > .fblabel { background: var(--bad-soft); color: var(--bad); }
.flow .fend { font-size: 12px; color: var(--muted); padding: 4px 10px; border: 1px dashed #c9cfdb; border-radius: 99px; background: #fff; }
.flow .fend.exit { color: var(--bad); border-color: #f1b5ae; }
.flow-dialog { border: 0; border-radius: 12px; padding: 20px; width: min(640px, calc(100% - 32px)); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.flow-dialog::backdrop { background: rgba(20,27,45,.45); }

/* Acceso */
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.auth .card { width: 100%; max-width: 380px; }

@media (max-width: 860px) {
  .layout { flex-direction: column; }
  .side { width: 100%; flex: none; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 16px; }
  .side .grow, .side .small { display: none; }
  .side select { width: auto; margin: 0; }
  .brand { padding: 4px 10px; }
  .main { padding: 18px 16px 40px; }
}
