:root {
  --bg: #f6f7f9;
  --fg: #1a1f2c;
  --muted: #6b7280;
  --border: #e3e6ec;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --ok: #16a34a;
  --warn: #d97706;
  --err: #dc2626;
  --card: #ffffff;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Helvetica, Arial, sans-serif; font-size: 14px; line-height: 1.4; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

nav.top {
  background: #111827; color: #fff; padding: .6rem 1rem;
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
}
nav.top a { color: #e5e7eb; padding: .35rem .7rem; border-radius: .35rem; }
nav.top a:hover { background: #1f2937; text-decoration: none; }
nav.top a.active { background: #2563eb; color: #fff; }
nav.top .brand { font-weight: 700; margin-right: 1rem; font-size: 1.05rem; }
nav.top .spacer { flex: 1; }
nav.top .meta { color: #9ca3af; font-size: .8rem; }

main { max-width: 1280px; margin: 0 auto; padding: 1.2rem; }
h1 { font-size: 1.4rem; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; margin: 1.5rem 0 .6rem; }
h3 { font-size: 1rem; margin: 1rem 0 .4rem; }

.ops-hero {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: .75rem;
  padding: 1.1rem 1.2rem;
  margin-bottom: 1rem;
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 1rem;
}
.ops-hero h1 { margin: .15rem 0 .25rem; font-size: 1.65rem; }
.eyebrow { color: var(--accent); font-size: .72rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .08em; }
.hero-copy { margin: 0; color: var(--muted); max-width: 44rem; }
.hero-status { min-width: 380px; display: flex; flex-direction: column;
  align-items: flex-end; justify-content: space-between; gap: .8rem; }
.status-pill {
  display: inline-flex; align-items: center; gap: .35rem; border-radius: 999px;
  padding: .35rem .75rem; font-size: .78rem; font-weight: 700;
}
.status-pill::before { content: ""; width: .5rem; height: .5rem; border-radius: 50%; background: currentColor; }
.status-pill.operativo, .badge.operativo { background: #dcfce7; color: #166534; }
.status-pill.atencion, .badge.atencion { background: #fef3c7; color: #92400e; }
.status-pill.critico, .badge.critico { background: #fee2e2; color: #991b1b; }
.hero-meta { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: .5rem; width: 100%; }
.hero-meta div { border: 1px solid var(--border); border-radius: .5rem;
  padding: .55rem .65rem; background: #fafbfc; }
.hero-meta span { display: block; color: var(--muted); font-size: .7rem;
  text-transform: uppercase; letter-spacing: .04em; }
.hero-meta strong { display: block; margin-top: .15rem; font-size: .82rem; }

.ops-kpis { display: grid; grid-template-columns: repeat(5, minmax(150px, 1fr));
  gap: .8rem; margin-bottom: 1rem; }
.ops-kpi {
  background: #fff; border: 1px solid var(--border); border-left: 4px solid #cbd5e1;
  border-radius: .65rem; padding: .85rem .9rem; min-height: 104px;
}
.ops-kpi.primary { border-left-color: var(--accent); }
.ops-kpi.warn { border-left-color: var(--warn); }
.ops-kpi.danger { border-left-color: var(--err); }
.ops-kpi span { color: var(--muted); font-size: .72rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .04em; }
.ops-kpi strong { display: block; font-size: 1.7rem; line-height: 1.1; margin-top: .35rem; }
.ops-kpi small { display: block; color: var(--muted); margin-top: .35rem; font-size: .75rem; }

.ops-layout { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 1rem; }
.ops-main, .ops-side { display: flex; flex-direction: column; gap: 1rem; min-width: 0; }
.panel { background: #fff; border: 1px solid var(--border); border-radius: .7rem;
  padding: 1rem; min-width: 0; }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between;
  gap: 1rem; margin-bottom: .8rem; }
.panel-head h2 { margin: 0; font-size: 1rem; }
.panel-head p { margin: .2rem 0 0; color: var(--muted); font-size: .8rem; }
.panel-head.compact { margin-bottom: .7rem; }

.attention-list { display: flex; flex-direction: column; gap: .55rem; }
.attention-item { border: 1px solid var(--border); border-left: 4px solid #cbd5e1;
  border-radius: .5rem; padding: .65rem .7rem; background: #fafbfc; }
.attention-item strong { display: block; font-size: .86rem; }
.attention-item span { display: block; color: var(--muted); font-size: .76rem; margin-top: .12rem; }
.attention-item.ok { border-left-color: var(--ok); background: #f0fdf4; }
.attention-item.warn { border-left-color: var(--warn); background: #fffbeb; }
.attention-item.danger { border-left-color: var(--err); background: #fef2f2; }

.facts { margin: 0; display: flex; flex-direction: column; gap: .55rem; }
.facts div { display: grid; grid-template-columns: 86px minmax(0, 1fr); gap: .6rem; }
.facts dt { color: var(--muted); font-size: .75rem; }
.facts dd { margin: 0; font-weight: 600; min-width: 0; overflow-wrap: anywhere; }

.quick-actions { display: grid; grid-template-columns: 1fr; gap: .45rem; }
.quick-actions .btn { text-align: center; }

.bot-distribution { display: flex; flex-direction: column; gap: .85rem; }
.bot-row { border: 1px solid var(--border); border-radius: .55rem; padding: .75rem;
  background: #fafbfc; }
.bot-row-top { display: flex; justify-content: space-between; gap: 1rem; margin-bottom: .5rem; }
.bot-row-top span { color: var(--muted); font-size: .8rem; }
.stackbar { display: flex; height: .6rem; background: #e5e7eb; border-radius: 999px;
  overflow: hidden; }
.stackbar i { display: block; min-width: 0; }
.stackbar .ok { background: var(--ok); }
.stackbar .info { background: var(--accent); }
.stackbar .warn { background: var(--warn); }
.stackbar .muted { background: #9ca3af; }
.bot-row-meta { display: flex; flex-wrap: wrap; gap: .7rem; margin-top: .55rem;
  color: var(--muted); font-size: .75rem; }
.bot-row-meta span { display: inline-flex; align-items: center; gap: .25rem; }

.compact-table th, .compact-table td { padding: .45rem .5rem; font-size: .8rem; }
.table-scroll { width: 100%; max-width: 100%; overflow-x: auto; }
.table-scroll table { min-width: 940px; }

.card { background: var(--card); border: 1px solid var(--border);
  border-radius: .5rem; padding: 1rem; margin-bottom: 1rem; }

.toolbar { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap;
  margin-bottom: .8rem; }
.toolbar input[type=text], .toolbar select { padding: .4rem .6rem; }
.toolbar .spacer { flex: 1; }

button, .btn {
  display: inline-block; padding: .45rem .8rem; border-radius: .35rem;
  border: 1px solid var(--border); background: #fff; color: var(--fg);
  cursor: pointer; font-size: .9rem; text-decoration: none;
}
button:hover, .btn:hover { background: #f3f4f6; text-decoration: none; }
.btn.primary, button.primary { background: var(--accent); color: #fff;
  border-color: var(--accent); }
.btn.primary:hover, button.primary:hover { background: var(--accent-hover); color: #fff; }
.btn.danger, button.danger { background: var(--err); color: #fff;
  border-color: var(--err); }
.btn.danger:hover, button.danger:hover { background: #b91c1c; color: #fff; }
.btn.small { padding: .25rem .55rem; font-size: .8rem; }
.btn.ghost { background: transparent; }

input[type=text], input[type=email], input[type=number], input[type=date], input[type=datetime-local],
input[type=password], select, textarea {
  padding: .4rem .55rem; border: 1px solid var(--border); border-radius: .3rem;
  background: #fff; font-size: .9rem; font-family: inherit;
}
textarea { width: 100%; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
label { display: block; margin: .4rem 0 .2rem; font-weight: 600; font-size: .85rem; }
.field { margin-bottom: .8rem; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: .8rem; }

table { width: 100%; border-collapse: collapse; background: #fff;
  border: 1px solid var(--border); border-radius: .4rem; overflow: hidden; }
th, td { padding: .5rem .65rem; border-bottom: 1px solid var(--border);
  text-align: left; vertical-align: top; font-size: .85rem; }
th { background: #f9fafb; font-weight: 600; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #fafbfc; }

.flash { padding: .55rem .8rem; border-radius: .35rem; margin-bottom: .8rem;
  border: 1px solid; }
.flash.ok { background: #ecfdf5; border-color: #a7f3d0; color: #065f46; }
.flash.err { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.flash.warn { background: #fffbeb; border-color: #fde68a; color: #92400e; }

.badge { display: inline-block; padding: .15rem .55rem; border-radius: .8rem;
  font-size: .75rem; font-weight: 600; background: #e5e7eb; color: #374151; }
.badge.ok { background: #dcfce7; color: #166534; }
.badge.warn { background: #fef3c7; color: #92400e; }
.badge.err { background: #fee2e2; color: #991b1b; }
.badge.muted { background: #e5e7eb; color: #6b7280; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px,1fr));
  gap: .8rem; margin-bottom: 1rem; }
.kpi { background: #fff; border: 1px solid var(--border); border-radius: .5rem;
  padding: .8rem 1rem; }
.kpi .label { color: var(--muted); font-size: .75rem; text-transform: uppercase;
  letter-spacing: .04em; }
.kpi .value { font-size: 1.5rem; font-weight: 700; margin-top: .15rem; }

.control-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1rem; margin-bottom: 1rem; }
.mini-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: .6rem; }
.mini-kpis > div { border: 1px solid var(--border); border-radius: .4rem;
  padding: .55rem .65rem; background: #fafbfc; }
.mini-kpis .label { display: block; color: var(--muted); font-size: .72rem;
  text-transform: uppercase; letter-spacing: .04em; margin: 0 0 .2rem; }
.mini-kpis strong { display: block; font-size: 1.15rem; }

.muted { color: var(--muted); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

.progress { background: #e5e7eb; border-radius: .35rem; overflow: hidden;
  height: .6rem; margin: .4rem 0; }
.progress > div { background: var(--accent); height: 100%; transition: width .3s ease; }

pre.log { background: #111827; color: #d1d5db; padding: .8rem; border-radius: .4rem;
  max-height: 50vh; overflow: auto; font-size: .78rem; line-height: 1.4;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.dot { display: inline-block; width: .55rem; height: .55rem; border-radius: 50%;
  background: #9ca3af; margin-right: .3rem; vertical-align: middle; }
.dot.ok { background: #16a34a; }
.dot.info { background: #2563eb; }
.dot.warn { background: #d97706; }
.dot.err { background: #dc2626; }
.dot.muted { background: #9ca3af; }

.pager { margin-top: .8rem; display: flex; gap: .3rem; align-items: center; }
.pager .badge { background: #fff; border: 1px solid var(--border); }

details.row > summary { cursor: pointer; padding: .25rem 0; }
details.row[open] { background: #fafbfc; }

.help { color: var(--muted); font-size: .8rem; margin-top: .2rem; }

.inline-action {
  display: inline-flex;
  gap: .35rem;
  align-items: center;
  justify-content: flex-end;
  margin: 0;
}
.checkline {
  display: inline-flex;
  gap: .25rem;
  align-items: center;
  margin: 0;
  color: var(--muted);
  font-size: .72rem;
  font-weight: 500;
  white-space: nowrap;
}

.excluded-field,
.excluded-editor {
  grid-column: 1 / -1;
}
.excluded-list {
  display: flex;
  flex-direction: column;
  gap: .45rem;
  margin-bottom: .5rem;
}
.excluded-row {
  display: grid;
  grid-template-columns: 130px 160px 160px auto;
  gap: .45rem;
  align-items: center;
  max-width: 660px;
}
.excluded-row.invalid input,
.excluded-row.invalid select {
  border-color: var(--err);
  background: #fff7f7;
}
.err-text {
  color: var(--err);
}

/* ---- Mini-visor de consola del bot (bots.html / _bot_console.html) ---- */
.console-details { margin-bottom: .4rem; }
.bot-console { margin-top: .4rem; }
.bot-console-head {
  display: flex; align-items: center; gap: .4rem; flex-wrap: wrap;
  font-size: .78rem; margin-bottom: .35rem;
}
.status-dot {
  display: inline-block; width: .7rem; height: .7rem; border-radius: 50%;
  flex: 0 0 auto;
}
.status-dot.ok { background: #16a34a; box-shadow: 0 0 0 3px #16a34a22; }
.status-dot.err { background: #dc2626; box-shadow: 0 0 0 3px #dc262622; }
.status-dot.muted { background: #9ca3af; box-shadow: 0 0 0 3px #9ca3af22; }
.live-tag { color: #16a34a; font-size: .7rem; }
.console-pre {
  background: #0b1020; color: #cbd5e1;
  padding: .7rem .8rem; border-radius: .4rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .72rem; line-height: 1.35;
  max-height: 320px; overflow: auto; white-space: pre-wrap; word-break: break-word;
  margin: 0;
}
.console-pre.muted { color: #9ca3af; background: #1118270d; }

/* ---- Validación de throttle: indicador HTMX + resultado inline ---- */
.htmx-indicator { display: none; color: #2563eb; font-size: .72rem; }
.htmx-request .htmx-indicator { display: inline; }
.htmx-request button { opacity: .55; }
.val-result:empty { display: none; }
.val-msg {
  font-size: .74rem; padding: .35rem .5rem; border-radius: .35rem;
  margin-top: .3rem; text-align: left; white-space: normal;
}
.val-msg.ok { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.val-msg.warn { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.val-msg.err { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }

@media (max-width: 980px) {
  .ops-hero, .hero-status { align-items: stretch; }
  .ops-hero { flex-direction: column; }
  .hero-status { min-width: 0; }
  .ops-kpis { grid-template-columns: repeat(2, minmax(150px, 1fr)); }
  .ops-layout { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  main { padding: .8rem; }
  .hero-meta { grid-template-columns: 1fr; }
  .ops-kpis { grid-template-columns: 1fr; }
  .ops-hero h1 { font-size: 1.35rem; }
  .excluded-row { grid-template-columns: 1fr; max-width: none; }
}
