:root {
  --bg: #f4f6fa; --panel: #ffffff; --panel2: #f0f3f8; --text: #18212f; --muted: #627089;
  --border: #dde3ec; --primary: #1f6feb; --primary-h: #1a5fd0; --primary-soft: rgba(31,111,235,.1);
  --green: #13854e; --green-soft: rgba(19,133,78,.12); --red: #c93439; --red-soft: rgba(201,52,57,.1);
  --amber: #a86a00; --amber-soft: rgba(214,140,0,.14); --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  /* Texto de las líneas de log sobre --panel2 (contraste AA a 12px) */
  --log-err: #b42328; --log-ok: #0d6b3c; --log-aviso: #8a5300; --log-paso: #1a5fd0;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141d; --panel: #171e2b; --panel2: #1f2838; --text: #e5eaf3; --muted: #8e9bb3;
    --border: #2b3547; --primary: #4c8dff; --primary-h: #3a7bf0; --primary-soft: rgba(76,141,255,.15);
    --green: #3ccf8e; --green-soft: rgba(60,207,142,.14); --red: #f0696e; --red-soft: rgba(240,105,110,.14);
    --amber: #f2b33d; --amber-soft: rgba(242,179,61,.15); --shadow: none;
    --log-err: #f0696e; --log-ok: #3ccf8e; --log-aviso: #f2b33d; --log-paso: #6ea2ff;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
[hidden] { display: none !important; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h2 { font-size: 20px; margin: 0; }
h3 { font-size: 15px; margin: 0 0 12px; }
small, .muted { color: var(--muted); }
code, .mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 13px; }

/* ── Marca ── */
.brand { display: flex; align-items: center; gap: 10px; }
.brand b { display: block; font-size: 15px; }
.brand small { display: block; font-size: 12px; }
.logo { width: 30px; height: 30px; border-radius: 8px; background: var(--primary); flex: none;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2 4 5v6c0 5 3.4 9.7 8 11 4.6-1.3 8-6 8-11V5l-8-3z'/%3E%3C/svg%3E") center/contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2 4 5v6c0 5 3.4 9.7 8 11 4.6-1.3 8-6 8-11V5l-8-3z'/%3E%3C/svg%3E") center/contain no-repeat; }

/* ── Login ── */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; display: grid; gap: 14px; padding: 28px; }
.login-card .brand { margin-bottom: 6px; }
.login-card form { display: grid; gap: 14px; }

/* ── Cabecera ── */
.top { display: flex; align-items: center; gap: 24px; padding: 10px 24px; background: var(--panel);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
#nav { display: flex; gap: 2px; flex: 1; flex-wrap: wrap; }
#nav a { padding: 8px 12px; border-radius: 8px; color: var(--muted); font-weight: 500; }
#nav a:hover { background: var(--panel2); text-decoration: none; color: var(--text); }
#nav a.active { color: var(--primary); background: var(--primary-soft); }
.me { display: flex; align-items: center; gap: 8px; }
.role { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--primary-soft); color: var(--primary); font-weight: 600; }
main { max-width: 1200px; margin: 0 auto; padding: 24px; }

/* ── Bloques ── */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); padding: 20px; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .spacer { flex: 1; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; box-shadow: var(--shadow); }
.stat span { display: block; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat b { font-size: 24px; font-variant-numeric: tabular-nums; }
.stat b small { font-size: 13px; font-weight: 500; }
.stat b .pill { font-size: 13px; vertical-align: middle; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar input[type=search] { flex: 1; min-width: 220px; }

/* ── Formularios ── */
label { display: grid; gap: 5px; font-size: 13px; font-weight: 500; }
label small { font-weight: 400; }
input, select, textarea { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 11px; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
textarea { width: 100%; resize: vertical; font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
.form { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.form .full { grid-column: 1 / -1; }
.form .rest { grid-column: 2 / -1; }   /* el resto de la fila, tras el primer campo */
.form-next { margin-top: 14px; }
.form label.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }
.actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.err-msg { color: var(--red); margin: 0; font-size: 13px; }
.hint { color: var(--muted); font-size: 13px; margin: 6px 0 14px; }

/* ── Botones ── */
.btn { font: inherit; font-weight: 500; border: 1px solid var(--border); background: var(--panel); color: var(--text);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { background: var(--panel2); text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-h); }
.btn.danger { color: var(--red); border-color: var(--red-soft); }
.btn.danger:hover { background: var(--red-soft); }
.btn.danger.strong { background: var(--red); border-color: var(--red); color: #fff; }
.btn.danger.strong:hover { filter: brightness(.92); }
.btn.ghost { border-color: transparent; background: none; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.block { width: 100%; justify-content: center; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ── Tablas ── */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 12px; background: var(--panel); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; background: var(--panel2); }
tr:last-child td { border-bottom: none; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: var(--panel2); }
td.r, th.r { text-align: right; }
.empty { text-align: center; color: var(--muted); padding: 32px; }
.pager { display: flex; align-items: center; gap: 8px; justify-content: flex-end; margin-top: 10px; color: var(--muted); }

/* ── Estados ── */
.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 99px; white-space: nowrap; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.on, .pill.active { background: var(--green-soft); color: var(--green); }
.pill.off { background: var(--panel2); color: var(--muted); }
.pill.revoked, .pill.error { background: var(--red-soft); color: var(--red); }
.pill.pending { background: var(--amber-soft); color: var(--amber); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.results { display: grid; gap: 4px; margin-top: 6px; max-height: 190px; overflow-y: auto; }
.opt { font: inherit; text-align: left; background: var(--panel2); border: 1px solid var(--border); color: var(--text); border-radius: 8px; padding: 6px 10px; cursor: pointer; }
.opt:hover { border-color: var(--primary); background: var(--primary-soft); }
.chip { font-size: 12px; padding: 2px 8px; border-radius: 6px; background: var(--panel2); border: 1px solid var(--border); }

/* ── Detalle ── */
/* minmax(0, …): el valor nunca empuja la tarjeta (tarjetas angostas, p. ej. 3 por fila) */
dl.kv { display: grid; grid-template-columns: minmax(96px, 150px) minmax(0, 1fr); gap: 8px 16px; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; min-width: 0; word-break: break-word; }
/* Un nombre largo (servicio, versión) parte dentro de su píldora en vez de salirse */
dl.kv dd .pill { white-space: normal; overflow-wrap: anywhere; max-width: 100%; }
.big-dl { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; padding: 18px 20px; border-radius: 12px;
  background: var(--primary-soft); border: 1px solid var(--border); margin-bottom: 16px; }
.big-dl .t { flex: 1; min-width: 240px; }
.big-dl b { font-size: 16px; }

/* ── Diálogos y avisos ── */
dialog { border: none; border-radius: 14px; padding: 0; background: var(--panel); color: var(--text); width: min(460px, calc(100vw - 32px)); box-shadow: 0 20px 50px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(10,15,25,.5); }
.dlg { padding: 22px; display: grid; gap: 12px; min-width: 0; overflow-wrap: anywhere; }
.dlg > * { min-width: 0; }
dialog.confirm-wide { width: min(90vw, 760px); }
.dlg-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg);
  padding: 10px 18px; border-radius: 10px; opacity: 0; transition: .2s; pointer-events: none; z-index: 50; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translateX(-50%); }
.toast.err { background: var(--red); color: #fff; }
.note { padding: 12px 14px; border-radius: 10px; background: var(--amber-soft); color: var(--text); font-size: 13px; margin-bottom: 14px; }

@media (max-width: 720px) {
  .top { padding: 10px 16px; gap: 10px; }
  main { padding: 16px; }
  dl.kv { grid-template-columns: 1fr; gap: 2px; }
  dl.kv dd { margin-bottom: 8px; }
  .hide-sm { display: none; }
  .form .rest { grid-column: 1 / -1; }
}

/* ── Puertos / avisos ── */
.stat.warn { border-color: var(--amber); background: var(--amber-soft); }
.stat[data-act] { cursor: pointer; }
.warn-t { color: var(--amber); font-weight: 600; }
tr.dim td { opacity: .55; }
.nowrap { white-space: nowrap; }
table.mini td { padding: 6px 8px; font-size: 13px; }
ol.steps { margin: 0; padding-left: 20px; display: grid; gap: 8px; }
ol.steps code { white-space: nowrap; }
a.chip:hover { text-decoration: none; border-color: var(--primary); }

/* ── Despliegues ── */
pre.out { white-space: pre-wrap; word-break: break-word; max-height: 320px; overflow: auto; background: var(--panel2);
  border: 1px solid var(--border); border-radius: 8px; padding: 10px; font-size: 12px; margin: 6px 0 0; }
details summary { cursor: pointer; color: var(--primary); font-size: 13px; margin-top: 6px; }
.var-row { margin-bottom: 6px; }
.big-dl .actions .btn { white-space: nowrap; }

/* ── Accesibilidad ── */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip { position: absolute; left: 8px; top: -48px; z-index: 100; background: var(--primary); color: #fff; padding: 8px 14px; border-radius: 8px; }
.skip:focus { top: 8px; text-decoration: none; }
:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; border-radius: 6px; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline-offset: 0; }
main:focus { outline: none; }
.req { color: var(--red); }
.brand-title { font-size: 15px; margin: 0; }
[aria-busy="true"] { cursor: progress; opacity: .7; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; } }
tbody tr.click:focus-visible { outline-offset: -3px; }

/* ── Navegación por secciones ── */
.subnav { display: flex; gap: 4px; padding: 0 24px; background: var(--panel); border-bottom: 1px solid var(--border); overflow-x: auto; position: sticky; top: 51px; z-index: 4; }
.subnav a { padding: 10px 12px; color: var(--muted); font-weight: 500; border-bottom: 2px solid transparent; white-space: nowrap; }
.subnav a:hover { color: var(--text); text-decoration: none; }
.subnav a.active { color: var(--primary); border-bottom-color: var(--primary); }
.section-title { margin: 28px 0 10px; }
button.stat { font: inherit; color: inherit; text-align: left; cursor: pointer; }
button.stat:hover { border-color: var(--primary); }
.actions.start { justify-content: flex-start; }
.actions.subtle { margin-top: 4px; }
.grid2.tight { gap: 10px; margin-top: 12px; }
.page-head.tight { margin-bottom: 6px; }
.grid2 > * { min-width: 0; }
.mini-card { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; background: var(--panel2); display: grid; gap: 6px; align-content: start; }

/* ── Flujo y pipeline de pasos ── */
ol.flow { list-style: none; padding: 0; margin: 0 0 14px; display: flex; flex-wrap: wrap; gap: 6px; font-size: 13px; color: var(--muted); }
ol.flow li { display: flex; align-items: center; gap: 6px; padding: 4px 10px 4px 4px; border-radius: 99px; background: var(--panel2); }
ol.flow b { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: var(--primary); color: #fff; font-size: 11px; }
ol.pipe { list-style: none; padding: 0; margin: 8px 0; display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
/* Los pasos pasan a otra línea dentro de su tarjeta o diálogo (listas largas de servicios, rutas) */
ol.pipe li { font-size: 12.5px; padding: 4px 9px; border-radius: 8px; border: 1px solid var(--border); background: var(--panel); white-space: normal; overflow-wrap: anywhere; max-width: 100%; }
.tip { text-decoration: underline dotted; cursor: help; }
ol.pipe li:not(:last-child)::after { content: "→"; margin-left: 8px; color: var(--muted); }
ol.pipe.compact li { padding: 2px 7px; font-size: 12px; }
.preview { margin-top: 10px; }
.steps-edit { border: 1px solid var(--border); border-radius: 10px; padding: 12px; margin: 0; }
.steps-edit legend { font-weight: 600; padding: 0 6px; }
#stepList { list-style: none; padding: 0; margin: 0 0 10px; display: grid; gap: 8px; }
.step-row { border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; background: var(--panel2); display: grid; gap: 6px; }
.step-head { display: flex; align-items: center; gap: 6px; }
.step-head .num { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); font-size: 12px; font-weight: 700; }
.step-head .spacer { flex: 1; }
.param { font-weight: 400; }
/* Flavor compuesto: bloques (uno por flavor que lo compone), en orden */
.chip.info { background: var(--primary-soft); color: var(--primary); border-color: transparent; font-weight: 600; }
.chip.lab { background: var(--amber-soft); color: var(--amber); border-color: var(--amber); font-weight: 600; }
.card.composite { border-left: 3px solid var(--primary); }
.parts { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin: 0 0 4px; }
ol.pipe-groups { list-style: none; padding: 0; margin: 8px 0; display: grid; gap: 6px; }
.pipe-group { border: 1px dashed var(--border); border-radius: 10px; padding: 6px 10px; background: var(--panel2); }
.pipe-group ol.pipe { margin: 4px 0 0; }
.grp-name { font-size: 12px; font-weight: 600; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.grp-name .num { display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); font-size: 11px; }
ol.pipe-groups.compact { gap: 4px; }
ol.pipe-groups.compact .pipe-group { padding: 4px 8px; }
#partList { list-style: none; padding: 0; margin: 0 0 10px; display: grid; gap: 8px; }
fieldset.seg { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 6px 16px; }
fieldset.seg legend { font-weight: 600; padding: 0; margin-bottom: 4px; }
fieldset.seg label { display: inline-flex; align-items: center; gap: 6px; font-weight: 400; }

@media (max-width: 720px) {
  .subnav { padding: 0 12px; top: 0; position: static; }
}

/* ── Formularios: etiqueta + asterisco en la misma línea; filas de cabecera de tabla ── */
label > .lbl { display: inline; }
.form input, .form select, .form textarea { width: 100%; }
.form input[type=checkbox] { width: auto; }
tbody th { text-transform: none; letter-spacing: 0; font-size: 14px; color: var(--text); background: none; font-weight: 600; }
.dlg .muted p, .dlg > .muted { margin: 0; }

/* El foco y los anclajes no quedan tapados por la cabecera fija (WCAG 2.2 · 2.4.11) */
html { scroll-padding-top: 120px; }

/* ── Código de activación (instalador genérico) ── */
.act-code { font-size: 34px; font-weight: 700; letter-spacing: .12em; text-align: center; padding: 16px 10px; border-radius: 10px;
  background: var(--primary-soft); color: var(--primary); border: 1px dashed var(--primary); user-select: all; word-break: break-all; }

/* ── Archivos de las EESS ── */
.files-filter { align-items: flex-end; }
.files-filter label { min-width: 150px; }
.files-filter input[name=eess] { text-transform: uppercase; }
.files-filter input[name=eess]::placeholder { text-transform: none; }
.files-filter-btns { display: flex; gap: 8px; }
td.file-name { word-break: break-all; min-width: 140px; }
dialog.wide { width: min(960px, calc(100vw - 32px)); }
.file-preview { max-height: 70vh; overflow: auto; border: 1px solid var(--border); border-radius: 10px; background: var(--panel2); padding: 10px; }
.file-preview img { display: block; max-width: 100%; height: auto; margin: 0 auto; border-radius: 6px; }
.file-preview pre.out { max-height: none; margin: 0; border: 0; padding: 0; }
.sha { word-break: break-all; }

/* ── Color por línea en las salidas y logs (colorearLog en app.js) ── */
.log-err { color: var(--log-err); font-weight: 600; }
.log-ok { color: var(--log-ok); }
.log-aviso { color: var(--log-aviso); }
.log-paso { color: var(--log-paso); }

/* ── Terminales POS: alta en lote y códigos imprimibles ── */
tr.row-err td { background: var(--red-soft); }
tr.row-err input { border-color: var(--red); }
@media print {
  body:has(dialog.print-codes[open]) > :not(dialog.print-codes) { display: none !important; }
  dialog.print-codes { position: static; width: auto; max-height: none; box-shadow: none; color: #000; background: #fff; }
  dialog.print-codes .dlg-actions { display: none; }
}

/* ── Monitoreo: tarjetas que filtran, filtros que se acomodan y orden por columnas ── */
button.stat[aria-pressed="true"] { border-color: var(--primary); background: var(--primary-soft); box-shadow: inset 0 0 0 1px var(--primary); }
button.stat[aria-pressed="true"] span { color: var(--primary); }
.toolbar select { max-width: 100%; }
th .sort { background: none; border: 0; padding: 0; margin: 0; font: inherit; color: inherit; text-transform: inherit; letter-spacing: inherit; cursor: pointer; }
th .sort:hover { color: var(--primary); }
th .sort[data-dir="asc"]::after { content: " ▲"; }
th .sort[data-dir="desc"]::after { content: " ▼"; }
th .sort[data-dir] { color: var(--primary); }
@media (max-width: 720px) {
  .toolbar select { flex: 1 1 calc(50% - 4px); }
}

/* ── Ficha de la EESS: cabecera fija (código, nombre, estado) y pestañas ── */
/* --ficha-top lo calcula app.js (alto de la barra superior y de la subnav si está fija) */
.ficha-top { position: sticky; top: var(--ficha-top, 51px); z-index: 3; background: var(--bg);
  margin: -24px -24px 16px; padding: 12px 24px 0; border-bottom: 1px solid var(--border); }
.ficha-head { margin-bottom: 6px; gap: 6px 12px; }
.ficha-head h2 { font-size: 18px; min-width: 0; overflow-wrap: anywhere; }
.ficha-pills { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; }
.ficha-tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: thin; margin-bottom: -1px; }
.ficha-tabs [role=tab] { display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; color: var(--muted); font-weight: 500;
  border-bottom: 2px solid transparent; white-space: nowrap; }
.ficha-tabs [role=tab]:hover { color: var(--text); text-decoration: none; }
.ficha-tabs [role=tab][aria-selected="true"] { color: var(--primary); border-bottom-color: var(--primary); }
.ficha-tabs [role=tab]:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; border-radius: 6px 6px 0 0; }
.ficha-tabs [role=tab][hidden] { display: none; }
.tab-badge { font-size: 11px; font-weight: 600; padding: 0 7px; border-radius: 99px; background: var(--panel2); border: 1px solid var(--border); color: var(--muted); }
.tab-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--red); flex: none; }
.tab-badge[hidden], .tab-dot[hidden] { display: none; }
.ficha-panel:focus { outline: none; }
/* El primer bloque de cada panel no lleva el margen que lo separaba de la tarjeta anterior */
.ficha-panel > :first-child, .ficha-panel > :first-child > :first-child { margin-top: 0 !important; }
.mw-linea { margin-top: 16px; padding: 12px 16px; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; }
@media (max-width: 720px) {
  .ficha-top { margin: -16px -16px 12px; padding: 8px 16px 0; }
  .ficha-head h2 { font-size: 16px; }
}
