/* Hallmark · shape: app screen · genre: modern-minimal · theme: brand · redesign: full
 * paper: #eef1f3 · accent: #234258 · display: Inter · body: Inter
 * nav: sidebar of modules (10 destinations), top bar under 60rem · signature: the ledger, totals over a double rule · states: empty, error, loading bars (kept)
 * axes: light/grotesk-sans/cool · posture: workbench · contrast: pass · v2.0.0 */
/* Hallmark · pre-emit critique: P4 H4 E4 S4 R3 V4 · weakest: R, the module title still lives inside each panel; a breadcrumb would need app.js state */
/* Hallmark · waive 24b · .pill, .chip, td input · las etiquetas, los filtros y los campos dentro de la grilla de ítems van en medios pasos de 2px para que la tabla sea densa */
@import url("./tokens.css");
@import url("./base.css");

body { font-size: var(--text-sm); line-height: 1.5; }
.oculto { display: none !important; }
[hidden] { display: none !important; }
h1, h2, h3, h4 { letter-spacing: var(--tracking-display); line-height: 1.25; }
h2 { max-width: none; margin: 0 0 var(--space-2xs); font-size: var(--text-lg); font-weight: 650;
     display: flex; align-items: center; gap: var(--space-xs); flex-wrap: wrap; }
h3 { max-width: none; margin: 0 0 var(--space-xs); font-size: var(--text-md); font-weight: 650;
     display: flex; align-items: center; gap: var(--space-xs); }
h4 { margin: var(--space-md) 0 var(--space-xs); font-size: var(--text-sm); }
p { max-width: none; }

/* ================================================== barra lateral */
#app { padding-left: var(--sidebar); min-height: 100vh; }
header {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar); z-index: var(--z-sticky-nav);
  display: flex; flex-direction: column; gap: var(--space-xs);
  background: var(--color-night); color: var(--color-night-ink);
  padding: var(--space-md) var(--space-sm) var(--space-sm);
  border-right: 1px solid var(--color-night-rule);
}
.marca { display: flex; flex-direction: column; gap: 1px; padding: var(--space-2xs) var(--space-xs) var(--space-sm);
         text-decoration: none; color: var(--color-night-ink); border-radius: var(--radius-control); }
.marca strong { font-family: var(--font-brand); font-weight: 400; font-size: var(--text-xl); line-height: 1.1; }
.marca small { color: var(--color-night-muted); font-size: var(--text-xs); }
.etq-empresa { color: var(--color-night-muted); font-size: var(--text-xs); padding: 0 var(--space-xs); }
header select {
  width: 100%; background-color: var(--color-night-2); color: var(--color-night-ink);
  border-color: var(--color-night-3); margin-bottom: var(--space-xs);
}
header select:hover { border-color: var(--color-night-muted); }
header select option { color: var(--color-ink); background: var(--color-paper-2); }

header nav { flex: 1 1 auto; min-height: 0; overflow-y: auto; display: flex; flex-direction: column;
             gap: var(--space-sm); padding: var(--space-xs) 0; border-top: 1px solid var(--color-night-rule);
             scrollbar-width: thin; scrollbar-color: var(--color-night-3) transparent; }
header nav .grupo { display: flex; flex-direction: column; gap: 1px; }
.grupo-titulo { color: var(--color-night-muted); font-size: var(--text-xs); padding: var(--space-2xs) var(--space-xs); }

.tab {
  display: flex; align-items: center; justify-content: flex-start; gap: var(--space-sm); width: 100%; min-height: 36px;
  padding: 0 var(--space-xs); border: 0; border-radius: var(--radius-control);
  background: transparent; color: var(--color-night-muted);
  font: inherit; font-size: var(--text-sm); font-weight: 500; text-align: left; white-space: nowrap; cursor: pointer;
  box-shadow: inset 3px 0 0 transparent;
  transition: background-color var(--dur-micro) var(--ease-out), color var(--dur-micro) var(--ease-out);
}
.tab .ico { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8;
            stroke-linecap: round; stroke-linejoin: round; }
@media (hover: hover) { .tab:not(:disabled):hover { background: var(--color-night-2); color: var(--color-night-ink); } }
.tab:active:not(:disabled) { background: var(--color-night-3); }
.tab.activo, .tab.activo:not(:disabled):hover { background: var(--color-night-3); color: var(--color-night-ink);
                                               box-shadow: inset 3px 0 0 var(--color-night-ink); }
.tab:disabled { opacity: 0.4; cursor: not-allowed; }
header :focus-visible { outline-color: var(--color-night-ink); outline-offset: -2px; }

.cuenta { display: flex; align-items: center; gap: var(--space-2xs); padding-top: var(--space-sm);
          border-top: 1px solid var(--color-night-rule); }
.tab-ayuda { width: 36px; justify-content: center; padding: 0; box-shadow: none; flex: none; }
.tab-ayuda.activo, .tab-ayuda.activo:not(:disabled):hover { box-shadow: none; }
header .yo, header .yo:not(:disabled):hover {
  flex: 1 1 auto; min-width: 0; display: flex; align-items: center; gap: var(--space-xs);
  min-height: 36px; padding: 0 var(--space-xs); border-radius: var(--radius-control);
  color: var(--color-night-ink); font-size: var(--text-sm); font-weight: 500; text-decoration: none; text-align: left;
}
header .yo:not(:disabled):hover { background: var(--color-night-2); }
header .yo span { overflow: hidden; text-overflow: ellipsis; }
header .yo small { color: var(--color-night-muted); font-weight: 400; }
header .yo svg { flex: none; }
header .yo:empty { display: none; }
header .salir, header .salir:not(:disabled):hover { color: var(--color-night-muted); padding: 0; width: 36px; height: 36px;
  justify-content: center; border-radius: var(--radius-control); }
header .salir:not(:disabled):hover { color: var(--color-night-ink); background: var(--color-night-2); }

/* ================================================== botones */
button, .boton {
  font: inherit; font-size: var(--text-sm); font-weight: 600; line-height: 1.2;
  min-height: var(--control); padding: 0 var(--space-md); border-radius: var(--radius-control); cursor: pointer;
  border: 1px solid var(--color-accent); background: var(--color-accent); color: var(--color-accent-ink);
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  white-space: nowrap;
  transition: background-color var(--dur-micro) var(--ease-out), border-color var(--dur-micro) var(--ease-out),
              color var(--dur-micro) var(--ease-out);
}
button:disabled { opacity: 0.55; cursor: not-allowed; }
button:not(:disabled):hover, .boton:hover { background: var(--color-accent-hover); border-color: var(--color-accent-hover); }
button:not(:disabled):active, .boton:active { transform: translateY(1px); }
:is(button, .boton, .tab, .carpeta, a):focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; }
.boton.secundario, button.secundario { background: var(--color-paper-2); color: var(--color-accent); border-color: var(--color-rule-2); }
.boton.secundario:hover, button.secundario:not(:disabled):hover {
  background: var(--color-accent-soft); border-color: var(--color-accent); color: var(--color-accent-hover);
}
button.peligro, button.peligro:not(:disabled):hover { background: var(--color-paper-2); color: var(--color-error); border-color: var(--color-error); }
button.peligro:not(:disabled):hover { background: var(--color-error-soft); }
input[type=file]::file-selector-button {
  font: inherit; font-weight: 600; min-height: 30px; padding: 0 var(--space-sm); margin-right: var(--space-sm); cursor: pointer;
  border: 1px solid var(--color-rule-2); border-radius: var(--radius-control); background: var(--color-paper-3); color: var(--color-accent);
}
input[type=file]::file-selector-button:hover { background: var(--color-accent-soft); }
.link, .link:not(:disabled):hover {
  background: none; border: none; color: var(--color-link); padding: var(--space-2xs); min-height: 0; cursor: pointer;
  font-weight: 600; text-decoration: none; border-radius: var(--radius-control);
}
.link:not(:disabled):hover { color: var(--color-link-hover); text-decoration: underline; }
.link:disabled { color: var(--color-muted); }

/* ================================================== layout */
section { padding: var(--space-lg); max-width: 1560px; margin: 0 auto; }
/* Panel: la ventana del módulo. Su primer título va en una banda gris,
   como el encabezado de un formulario contable. */
.caja {
  background: var(--color-paper-2); border: 1px solid var(--color-rule); border-radius: var(--radius-card);
  padding: var(--space-md) var(--space-lg) var(--space-lg); margin-bottom: var(--space-md);
}
.caja > :is(h2, h3):first-child, .caja > .fila-titulo:first-child {
  margin: calc(var(--space-md) * -1) calc(var(--space-lg) * -1) var(--space-md);
  padding: var(--space-sm) var(--space-lg); min-height: 48px;
  background: var(--color-paper-3); border-bottom: 1px solid var(--color-rule);
  border-radius: var(--radius-card) var(--radius-card) 0 0;
}
.caja > h2:first-child { font-size: var(--text-md); }
#lote-titulo { font-size: var(--text-xl); margin: var(--space-2xs) 0 var(--space-md); }
#volver { padding-left: 0; }
.ayuda { color: var(--color-muted); margin: 0 0 var(--space-sm); font-size: var(--text-sm); max-width: 100ch; }
:is(.ayuda, .param, #ayuda-articulos) code {
  background: var(--color-paper-3); border: 1px solid var(--color-rule); padding: 0 5px;
  border-radius: var(--radius-control); font-family: var(--font-mono); font-size: var(--text-xs);
}
.fila-titulo { display: flex; justify-content: space-between; align-items: center; gap: var(--space-sm); flex-wrap: wrap; margin-bottom: var(--space-sm); }
.fila-titulo > div { display: flex; gap: var(--space-xs); align-items: center; flex-wrap: wrap; }
.fila-titulo h3 { margin: 0; }
.descargas { display: flex; gap: var(--space-xs); flex-wrap: wrap; }

/* ================================================== campos */
form { display: flex; gap: var(--space-xs); flex-wrap: wrap; align-items: center; }
:where(input[type=text], input[type=search], input[type=password], input[type=number], input[type=date],
       input[type=month], select, input:not([type])) {
  font: inherit; font-size: var(--text-sm); padding: 0 10px; border: 1px solid var(--color-rule-2);
  border-radius: var(--radius-control); background: var(--color-paper-2); color: var(--color-ink); min-height: var(--control);
  transition: border-color var(--dur-micro) var(--ease-out);
}
input:where(:focus-visible), select:where(:focus-visible) { outline: 2px solid var(--color-focus); outline-offset: -1px; }
input:where(:hover), select:where(:hover) { border-color: var(--color-muted); }
input:disabled, select:disabled { opacity: 0.55; cursor: not-allowed; }
input::placeholder { color: var(--color-muted); }
select { cursor: pointer; }
label:has(> input[type=month]) { display: inline-flex; align-items: center; gap: var(--space-xs); font-weight: 600; }

/* ================================================== procesos del lote */
/* Los tres pasos como una tira de proceso numerada. */
.procesos { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 0; padding: 0; overflow: hidden; }
.proceso { padding: var(--space-md) var(--space-lg); border-right: 1px solid var(--color-rule);
           display: flex; flex-direction: column; align-items: flex-start; gap: var(--space-2xs); }
.proceso:last-child { border-right: none; }
.caja.procesos > .proceso > h3:first-child { margin: 0; padding: 0; min-height: 0; background: none; border: 0; }
.proceso .ayuda { margin-bottom: var(--space-sm); }
.proceso > button { margin-right: 6px; }
.proceso > div:not(.barra), .proceso > .alerta { align-self: stretch; }
.barra { height: 6px; background: var(--color-rule); border-radius: 1px; margin-top: var(--space-sm); overflow: hidden; align-self: stretch; }
.barra > div { height: 100%; background: var(--color-ok); }
.barra.parcial > div { background: var(--color-warn-bar); }
.barra.error > div { background: var(--color-error); }
.barra.cancelado > div, .barra.interrumpido > div { background: var(--color-muted); }
.estado-job { font-size: var(--text-xs); color: var(--color-muted); margin-top: var(--space-2xs); display: block;
              max-height: 3.4em; overflow: hidden; cursor: pointer; }
.estado-job.abierto { max-height: none; }
.estado-job:not(.abierto)::after { content: " más"; color: var(--color-link); }
.resumen { display: flex; flex-wrap: wrap; gap: 6px; margin-top: var(--space-sm); }
.resumen p { margin: 0; }

/* ================================================== tablas: el libro */
table { width: 100%; border-collapse: separate; border-spacing: 0; font-variant-numeric: tabular-nums; font-size: var(--text-sm); }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--color-rule); vertical-align: top; }
th {
  font-size: var(--text-xs); font-weight: 600; color: var(--color-ink-2);
  position: sticky; top: 0; z-index: 1; background: var(--color-paper-3); white-space: nowrap;
  border-bottom: 1px solid var(--color-rule-2); border-top: 1px solid var(--color-rule-2);
}
tbody tr { transition: background-color var(--dur-micro) var(--ease-out); }
tbody tr:nth-child(even) > td { background: var(--color-paper-3); }
tbody tr:hover > td { background: var(--color-row-hover); }
td small { color: var(--color-muted); }
td.vacio, tbody tr:nth-child(even) > td.vacio { text-align: center; color: var(--color-muted); padding: var(--space-xl) 10px; background: var(--color-paper-2); }
.paginador { display: flex; gap: 6px; align-items: center; justify-content: flex-end;
             margin-top: var(--space-sm); color: var(--color-muted); font-size: var(--text-sm); }
.paginador .link:disabled { color: var(--color-rule-2); cursor: default; text-decoration: none; }
th[data-orden] { cursor: pointer; user-select: none; }
#tabla-items th { position: sticky; overflow: hidden; text-overflow: ellipsis; }
.redim { position: absolute; top: 0; right: 0; width: 12px; height: 100%; cursor: col-resize; touch-action: none; }
.redim::after { content: ""; position: absolute; top: 25%; bottom: 25%; right: 4px; width: 2px;
                background: var(--color-rule-2); opacity: 0; transition: opacity var(--dur-micro); }
th:hover .redim::after, .redimensionando .redim::after { opacity: 1; }
.redimensionando, .redimensionando * { cursor: col-resize !important; user-select: none; }
th[data-orden]:hover, th.ordenado { color: var(--color-accent); }
th[data-orden]::after { content: attr(data-flecha); }
td input, td select {
  width: 100%; border: 1px solid transparent; background: transparent; padding: var(--space-3xs) 6px;
  font: inherit; font-size: var(--text-sm); border-radius: var(--radius-control); min-height: 28px;
}
td input:hover, td select:hover { border-color: var(--color-rule-2); background: var(--color-paper-2); }
td input:focus-visible, td select:focus-visible { background: var(--color-paper-2); }
td input[type=checkbox] { width: auto; min-height: 0; accent-color: var(--color-accent); }
tr.editado > td { background: var(--color-edited) !important; }
.scroll { max-height: 65vh; overflow: auto; border: 1px solid var(--color-rule); border-radius: var(--radius-control); }
.scroll > table th { border-top: 0; }
.scroll-tabla { overflow-x: auto; }
.num, th.num { text-align: right; }
td.num input { text-align: right; }
/* Totales del libro: una raya doble, como se cierra una suma a mano. */
tfoot td { border-top: 3px double var(--color-ink-2); border-bottom: none; background: var(--color-paper-3); font-weight: 600; }

/* ================================================== etiquetas de estado */
.pill {
  display: inline-flex; align-items: center; gap: var(--space-2xs); white-space: nowrap;
  font-size: var(--text-xs); font-weight: 600; line-height: 1.5; padding: 0 7px; border-radius: var(--radius-control);
  background: var(--color-paper-3); color: var(--color-ink-2); border: 1px solid var(--color-rule);
}
.pill:empty { display: none; }
.pill.ia { background: var(--color-ia-soft); color: var(--color-ia); border-color: transparent; }
.pill.cache, .pill.regla { background: var(--color-ok-soft); color: var(--color-ok); border-color: transparent; }
.pill.similar { background: var(--color-warn-soft); color: var(--color-warn); border-color: transparent; }
.pill.manual { background: var(--color-accent-soft); color: var(--color-accent); border-color: transparent; }
.pill.error { background: var(--color-error-soft); color: var(--color-error); border-color: transparent; }
.pill.pendiente { background: var(--color-paper-3); color: var(--color-muted); }
a.pill { text-decoration: none; }
a.pill:hover { text-decoration: underline; }
td.soportes { white-space: nowrap; }
td.soportes small { white-space: normal; }

/* Avisos del plano, junto a Descargas: lo que hay que mirar antes de bajarlo. */
#revision-plano { margin-top: var(--space-md); gap: var(--space-xs); flex-direction: column; align-items: flex-start; }
#revision-plano .pill { border-radius: var(--radius-control); padding: 6px var(--space-sm); font-size: var(--text-sm); white-space: normal; }
#revision-plano .pill.error { border: 1px solid var(--color-error-rule); cursor: help; }
.aviso-plano { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2xs) var(--space-xs); }
.aviso-facturas { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3xs) 6px; font-size: var(--text-sm); }
.aviso-facturas .link { padding: var(--space-3xs) 6px; background: var(--color-paper-2); border: 1px solid var(--color-rule); }
.aviso-facturas .link:not(:disabled):hover { background: var(--color-accent-soft); border-color: var(--color-accent); }

/* ================================================== entrada */
.login {
  display: grid; place-items: center; min-height: 100vh; padding: var(--space-lg);
  background: var(--color-night);
}
.login form {
  flex-direction: column; align-items: stretch; width: 340px; max-width: 100%; background: var(--color-paper-2);
  padding: var(--space-xl) var(--space-lg) var(--space-lg); border-radius: var(--radius-card); gap: var(--space-sm);
  border-top: 4px solid var(--color-accent);
}
.login input, .login button { width: 100%; min-height: 40px; }
.logo-login { width: 160px; margin: 0 auto var(--space-xs); display: block; }
.login h1 { color: var(--color-night); font-family: var(--font-brand); font-weight: 400; text-align: center;
            margin: 0 auto; letter-spacing: 0; font-size: var(--text-xl); }
.login p { text-align: center; color: var(--color-muted); margin: 0 0 var(--space-xs); }
.error { color: var(--color-error); font-size: var(--text-sm); }

/* Notificación flotante. */
.aviso {
  position: fixed; bottom: var(--space-md); right: var(--space-md); background: var(--color-night); color: var(--color-night-ink);
  padding: var(--space-sm) var(--space-md); border-radius: var(--radius-card); z-index: var(--z-toast); max-width: 420px;
  box-shadow: var(--shadow-pop); font-size: var(--text-sm);
  animation: subir var(--dur-short) var(--ease-out);
}
@keyframes subir { from { transform: translateY(8px); opacity: 0; } }

/* La grilla de ítems necesita ancho real: con scroll horizontal las columnas
   editables (descripción y cuenta PUC) dejan de salir cortadas. */
#tabla-items { min-width: 1900px; }
#tabla-items th:nth-child(3), #tabla-items td:nth-child(3) { min-width: 320px; }
#tabla-items th:nth-child(8), #tabla-items td:nth-child(8) { min-width: 300px; }
#tabla-items th:nth-child(9), #tabla-items td:nth-child(9) { min-width: 110px; }
#tabla-items th:nth-child(10), #tabla-items td:nth-child(10) { min-width: 190px; }
#tabla-items td:nth-child(10) input { width: 55%; display: inline-block; text-align: right; }
#tabla-items td:nth-child(10) select { width: 42%; display: inline-block; }
#tabla-items td:nth-child(10) small { display: block; margin-top: 1px; font-size: 11px; line-height: 1.2; }
#tabla-items td:nth-child(10) small .pill { font-size: 10px; padding: 0 5px; }
#tabla-items td:nth-child(4), #tabla-items td:nth-child(7) { min-width: 80px; }
#tabla-items td:nth-child(5), #tabla-items td:nth-child(6) { min-width: 120px; }
#tabla-items th:nth-child(2), #tabla-items td:nth-child(2) { min-width: 170px; }
#tabla-items [data-medio-pago] { min-width: 90px; }
#tabla-cache { min-width: 1200px; }
#tabla-cache th:nth-child(3), #tabla-cache td:nth-child(3) { min-width: 300px; }
#tabla-cache th:nth-child(4), #tabla-cache td:nth-child(4) { min-width: 300px; }

/* ================================================== parámetros */
.param { display: grid; grid-template-columns: 240px 160px minmax(0, 1fr); gap: var(--space-md); align-items: start;
         padding: var(--space-sm) 0; border-bottom: 1px solid var(--color-rule); }
.param:last-child { border-bottom: none; }
.param label { font-weight: 600; font-size: var(--text-sm); display: flex; flex-direction: column; gap: var(--space-2xs); align-items: flex-start; }
.param small { color: var(--color-muted); }
#guardar-config { margin-top: var(--space-sm); }

tr.detalle > td, tbody tr:nth-child(even).detalle > td { background: var(--color-paper-3) !important; padding: var(--space-sm) var(--space-md); }
table.interna { background: var(--color-paper-2); border: 1px solid var(--color-rule); }
table.interna th { position: static; border-top: 0; }

/* ================================================== ficha flotante */
.modal { position: fixed; inset: 0; background: var(--color-scrim);
         display: grid; place-items: center; z-index: var(--z-modal); padding: var(--space-lg); animation: aparecer var(--dur-short) var(--ease-out); }
.modal-caja { background: var(--color-paper-2); border-radius: var(--radius-card); padding: var(--space-lg) var(--space-lg);
              max-width: 1100px; width: 100%; max-height: 88vh; overflow: auto; position: relative;
              border-top: 4px solid var(--color-accent); box-shadow: var(--shadow-pop); }
@keyframes aparecer { from { opacity: 0; } }
.modal-caja .cerrar, .modal-caja .cerrar:not(:disabled):hover {
  position: sticky; float: right; top: var(--space-2xs); margin: calc(var(--space-xs) * -1) calc(var(--space-xs) * -1) 0 0; font-size: var(--text-md); width: 34px; height: 34px;
  justify-content: center; color: var(--color-muted); z-index: 2; background: var(--color-paper-2); text-decoration: none;
}
.modal-caja .cerrar:not(:disabled):hover { background: var(--color-paper-3); color: var(--color-ink); }
.modal-caja h3 { font-size: var(--text-lg); margin-right: 30px; }
#modal-cuerpo > p:not(.ayuda) { display: flex; flex-wrap: wrap; gap: var(--space-xs); align-items: center; }
code.cufe { font-family: var(--font-mono); font-size: 11px; word-break: break-all; color: var(--color-muted); }

pre.xml { background: var(--color-paper-3); border: 1px solid var(--color-rule); border-radius: var(--radius-control);
          padding: var(--space-md); max-height: 45vh; overflow: auto; font-family: var(--font-mono); font-size: var(--text-xs);
          white-space: pre-wrap; word-break: break-word; }

/* Fila de campos sueltos (agregar empresa, certificado). */
.filtros { display: flex; flex-wrap: wrap; gap: var(--space-xs); align-items: center; margin: var(--space-md) 0 0; }

/* ================================================== barra de filtros */
.fb { margin-bottom: var(--space-md); }
.fb-fila { display: flex; flex-wrap: wrap; gap: var(--space-xs); align-items: center; }
.fb-buscar { position: relative; flex: 1 1 280px; max-width: 460px; }
.fb-buscar::before {
  content: ""; position: absolute; left: 11px; top: 50%; width: 14px; height: 14px; transform: translateY(-50%);
  background: var(--color-muted);
  mask: no-repeat center/14px url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E");
}
.fb-buscar input { width: 100%; padding-left: 32px; }
.fb-abrir { background: var(--color-paper-2); color: var(--color-accent); border-color: var(--color-rule-2); padding: 0 var(--space-sm); }
.fb-abrir::before {
  content: ""; width: 14px; height: 14px; background: currentColor;
  mask: no-repeat center/14px url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round'%3E%3Cpath d='M4 6h16M7 12h10M10 18h4'/%3E%3C/svg%3E");
}
.fb-abrir:not(:disabled):hover { background: var(--color-accent-soft); border-color: var(--color-accent); color: var(--color-accent-hover); }
.fb-abrir[aria-expanded=true], .fb-abrir.con-filtros { border-color: var(--color-accent); background: var(--color-accent-soft); }
.fb-n:empty { display: none; }
.fb-n { background: var(--color-accent); color: var(--color-accent-ink); border-radius: var(--radius-pill); font-size: 11px; min-width: 18px; height: 18px;
        display: inline-grid; place-items: center; padding: 0 5px; }
.fb-der { display: flex; gap: var(--space-xs); align-items: center; flex-wrap: wrap; margin-left: auto; }

/* Interruptor: la casilla de siempre con cara de casilla de formulario. */
.toggle {
  display: inline-flex; align-items: center; gap: var(--space-xs); cursor: pointer; user-select: none;
  border: 1px solid var(--color-rule-2); border-radius: var(--radius-control); padding: 0 var(--space-sm) 0 10px;
  font-size: var(--text-sm); font-weight: 500; background: var(--color-paper-2); min-height: var(--control);
}
.toggle:has(input:checked) { border-color: var(--color-accent); background: var(--color-accent-soft); color: var(--color-accent-hover); }
.toggle:has(input:focus-visible) { outline: 2px solid var(--color-focus); outline-offset: 2px; }
.toggle input {
  appearance: none; -webkit-appearance: none; margin: 0; width: 28px; height: 16px; border-radius: var(--radius-pill);
  background: var(--color-rule-2); position: relative; transition: background-color var(--dur-micro); cursor: pointer; flex: none;
}
.toggle input::before {
  content: ""; position: absolute; top: 2px; left: 2px; width: 12px; height: 12px; border-radius: 50%;
  background: var(--color-paper-2); transition: transform var(--dur-micro) var(--ease-out);
}
.toggle input:checked { background: var(--color-accent); }
.toggle input:checked::before { transform: translateX(12px); }

.fb-panel {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: var(--space-sm) var(--space-md);
  margin-top: 10px; padding: var(--space-md); background: var(--color-paper-3); border: 1px solid var(--color-rule); border-radius: var(--radius-control);
}
.fb-campo { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.fb-etq { font-size: var(--text-xs); font-weight: 600; color: var(--color-muted); }
.fb-campo.activo .fb-etq { color: var(--color-accent); }
.fb-rango { display: flex; align-items: center; gap: 6px; }
.fb-rango input { flex: 1 1 0; min-width: 0; }
.fb-rango span { color: var(--color-muted); font-size: var(--text-xs); }

details.multi { position: relative; }
details.multi summary {
  list-style: none; cursor: pointer; border: 1px solid var(--color-rule-2); border-radius: var(--radius-control);
  padding: 0 30px 0 10px; background: var(--color-paper-2); min-height: var(--control); line-height: calc(var(--control) - 2px);
  font-size: var(--text-sm); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; position: relative;
}
details.multi summary::after {
  content: ""; position: absolute; right: 11px; top: 50%; width: 10px; height: 10px; margin-top: -5px; background: var(--color-muted);
  mask: no-repeat center/10px url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='3' stroke-linecap='round'%3E%3Cpath d='m5 9 7 7 7-7'/%3E%3C/svg%3E");
}
details.multi summary::-webkit-details-marker { display: none; }
details.multi summary:focus-visible { outline: 2px solid var(--color-focus); outline-offset: -1px; }
details.multi[open] summary, .fb-campo.activo summary { border-color: var(--color-accent); }
.fb-campo.activo summary { background: var(--color-accent-soft); font-weight: 600; color: var(--color-accent-hover); }
.multi-lista {
  position: absolute; z-index: var(--z-dropdown); left: 0; margin-top: var(--space-2xs); min-width: 100%; width: max-content; max-width: min(380px, 86vw);
  background: var(--color-paper-2); border: 0; border-radius: var(--radius-control); padding: 6px;
  box-shadow: var(--shadow-pop);
}
.multi-buscar { width: 100%; margin-bottom: var(--space-2xs); }
.multi-ops { max-height: 280px; overflow: auto; }
.multi-ops label {
  display: flex; align-items: center; gap: var(--space-xs); padding: 6px var(--space-xs); border-radius: var(--radius-control); cursor: pointer; font-size: var(--text-sm);
}
.multi-ops label:hover { background: var(--color-paper-3); }
.multi-ops label span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.multi-ops label small { color: var(--color-muted); font-variant-numeric: tabular-nums; }
.multi-ops input { accent-color: var(--color-accent); margin: 0; }

.fb-chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 10px; }
.fb-chips:empty { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: var(--space-2xs); font-size: var(--text-sm); padding: var(--space-3xs) var(--space-2xs) var(--space-3xs) 10px;
  border-radius: var(--radius-control); background: var(--color-accent-soft); color: var(--color-accent-hover); border: 1px solid var(--color-rule-2);
  max-width: 100%;
}
.chip b { font-weight: 600; color: var(--color-accent); }
.chip button, .chip button:not(:disabled):hover {
  background: transparent; border: none; color: var(--color-accent); padding: 0; width: 22px; min-height: 22px;
  font-size: 11px; border-radius: var(--radius-control);
}
.chip button:not(:disabled):hover { background: var(--color-paper-2); color: var(--color-accent-hover); }
.fb-limpiar { font-size: var(--text-sm); }

/* Históricos y PDFs: carpetas año › mes a la izquierda, archivos a la derecha. */
.carpetas { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: var(--space-md); }
.arbol { display: flex; flex-direction: column; gap: 1px; max-height: 70vh; overflow: auto;
         border: 1px solid var(--color-rule); border-radius: var(--radius-control); padding: var(--space-2xs); align-self: start; }
.carpeta { display: flex; align-items: center; gap: var(--space-xs); background: none; border: none; min-height: 32px;
           border-radius: var(--radius-control); padding: 0 10px; font-weight: 500; color: var(--color-ink); text-align: left; cursor: pointer; text-decoration: none; }
.carpeta:not(:disabled):hover { background: var(--color-accent-soft); color: var(--color-ink); border: none; }
.carpeta.activa, .carpeta.activa:not(:disabled):hover { background: var(--color-accent); color: var(--color-accent-ink); }
.carpeta small { opacity: 0.75; margin-left: auto; font-variant-numeric: tabular-nums; }
.carpeta.anio { font-weight: 650; }
.carpeta.anio::before {
  content: ""; width: 14px; height: 14px; flex: none; background: currentColor;
  mask: no-repeat center/14px url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linejoin='round'%3E%3Cpath d='M3 6h6l2 2h10v11H3z'/%3E%3C/svg%3E");
}
.carpeta.mes { padding-left: 32px; text-transform: capitalize; }

/* Paso 3: facturas que quedaron sin PDF. */
.alerta { margin-top: var(--space-sm); padding: var(--space-sm) var(--space-md); border: 1px solid var(--color-error-rule);
          background: var(--color-error-soft); border-radius: var(--radius-control); font-size: var(--text-sm); }
.alerta strong { color: var(--color-error); }
.alerta ul { margin: 6px 0; padding-left: 18px; }
.alerta li small { display: block; color: var(--color-muted); }
.alerta .link { padding: 0; text-align: left; white-space: normal; }
.scroll-x { overflow-x: auto; }
.scroll-x td { white-space: nowrap; }

/* ================================================== ayuda */
.wiki { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: var(--space-md); align-items: start; }
.wiki-indice { position: sticky; top: var(--space-lg); display: flex; flex-direction: column; gap: 10px; padding: var(--space-sm); }
.wiki-indice input { width: 100%; }
.wiki-indice nav { display: flex; flex-direction: column; gap: 1px; max-height: 70vh; overflow: auto; }
.wiki-indice .carpeta { font-size: var(--text-sm); }
#ayuda-articulos article { scroll-margin-top: var(--space-lg); max-width: 90ch; }
#ayuda-articulos p { margin: 0 0 var(--space-sm); line-height: 1.65; }
#ayuda-articulos p, #ayuda-articulos li, #ayuda-articulos dd { color: var(--color-ink); }
#ayuda-articulos ol, #ayuda-articulos ul { padding-left: 20px; }
#ayuda-articulos li { margin-bottom: var(--space-2xs); line-height: 1.6; }
#ayuda-articulos dt { font-weight: 600; margin-top: 10px; }
#ayuda-articulos dd { margin: var(--space-3xs) 0 0; color: var(--color-muted); }

/* El detalle de la bitácora puede traer un JSON largo: que se parta. */
.detalle-bitacora { display: block; max-width: 38em; word-break: break-word; }

/* ================================================== roles */
/* Solo es comodidad: el backend rechaza con 403 lo que el rol no permite. */
body:not(.admin) .solo-admin { display: none !important; }
/* Cada permiso que falta pone body.sin-<permiso> y oculta sus controles. */
body.sin-lotes :is(.caja:has(#form-lote), #tabla-lotes [data-borrar]),
body.sin-jobs :is([data-job], [data-detener]),
body.sin-items :is(#guardar-items, label:has(#cruzar-medio-pago), #cruzar-gerencia),
body.sin-diccionario :is(label:has(#importar-cache), #aprobar-todo, #guardar-cache, #tabla-cache [data-borrar]),
body.sin-ajustes :is(label:has(#importar-rete), #confirmar-visibles, [data-confirmar], #guardar-config),
body.sin-empresas :is(#form-empresa, [data-guardar-empresa]),
body.sin-certificados [data-cargar-cert],
body.sin-descargas :is(.descargas, #zip-pdfs, #p-zip, #exportar-cache),
body.sin-gerencia #vista-gerencia .edita { display: none !important; }
body.sin-items #tabla-items :is(input, select, textarea),
body.sin-diccionario #tabla-cache :is(input, select, textarea),
body.sin-ajustes :is(#tabla-proveedores, #lista-config) :is(input, select, textarea),
body.sin-empresas #tabla-empresas :is(input, select, textarea),
body.sin-gerencia :is(#tabla-gf-cuentas, #tabla-gf-centros, #tabla-gf-rec, #tabla-gf-previa) :is(input, select, textarea)
  { pointer-events: none; opacity: 0.7; }
.tabla-roles td.si { color: var(--color-ok); font-weight: 600; }
.tabla-roles td.no { color: var(--color-muted); }
.tabla-roles th, .tabla-roles td.c { text-align: center; }
body.limitado #form-empresa { display: none !important; }

/* ================================================== gerencia financiera */
/* Sub-módulos como pestañas de un libro: la activa se pega al panel. */
.gf-sub { display: flex; gap: 0; flex-wrap: nowrap; overflow-x: auto; margin: var(--space-sm) 0 var(--space-md);
          border-bottom: 1px solid var(--color-rule-2); scrollbar-width: none; }
.gf-sub::-webkit-scrollbar { display: none; }
.gf-sub button, .gf-sub button:not(:disabled):hover {
  background: transparent; color: var(--color-muted); border: 0; border-radius: 0; min-height: 40px; padding: 0 var(--space-md);
  font-weight: 600; box-shadow: inset 0 -2px 0 transparent; margin-bottom: -1px;
}
.gf-sub button:not(.activo):not(:disabled):hover { color: var(--color-ink); background: var(--color-paper-3); }
.gf-sub button.activo, .gf-sub button.activo:not(:disabled):hover { color: var(--color-accent); box-shadow: inset 0 -2px 0 var(--color-accent); }
.gf-sub button:not(:disabled):active { transform: none; }
/* Saldos por cuenta: una fila de cifras, cada una con su raya izquierda. */
.gf-saldos { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0; margin-bottom: var(--space-md);
             border: 1px solid var(--color-rule); border-radius: var(--radius-control); }
.gf-saldos:empty { display: none; }
.gf-saldos div { padding: var(--space-xs) var(--space-md); border-right: 1px solid var(--color-rule); }
.gf-saldos small { display: block; color: var(--color-muted); }
.gf-saldos b { font-variant-numeric: tabular-nums; font-size: var(--text-lg); font-weight: 650; }
.negativo { color: var(--color-error); }
#gf-form { padding: var(--space-sm); background: var(--color-paper-3); border: 1px solid var(--color-rule); border-radius: var(--radius-control); margin: 0 0 var(--space-sm); }
#gf-form .gf-concepto { flex: 1 1 260px; }
#gf-form input[type=number] { width: 130px; }
#gf-form small.ayuda { margin: 0; }
#tabla-gf td.num, #tabla-gf-cons td, #tabla-gf-cuentas td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
#tabla-gf td:nth-child(7) { font-weight: 600; }
#tabla-gf tr.editando > td { background: var(--color-accent-soft); }
#tabla-gf-cons th, #tabla-gf-cons td { white-space: nowrap; }
#tabla-gf-cons th { position: static; }  /* dos filas de encabezado: sticky las encima */
#tabla-gf-cons tfoot td { font-weight: 600; }
#gf-admin h3 { margin: var(--space-md) 0 6px; font-size: var(--text-md); }
#tabla-gf-previa [data-c=nombre], #tabla-gf-cuentas [data-c=nombre], #tabla-gf-centros [data-c=nombre] { min-width: 240px; }
#tabla-gf-previa [data-c=tipo], #tabla-gf-cuentas [data-c=tipo] { min-width: 110px; }
#tabla-gf-rec input, #tabla-gf-rec select { min-width: 0; }
#tabla-gf-rec [data-c=descripcion] { min-width: 240px; }
#tabla-gf-rec [data-c=valor] { width: 120px; }
#tabla-gf-rec [data-c=meses] { width: 90px; }
#tabla-gf-rec [data-c=dia_desde], #tabla-gf-rec [data-c=dia_hasta] { width: 60px; }
#tabla-gf-gastos td small { display: block; }
#tabla-gf-rec [data-c=tipo], #tabla-gf-rec [data-c=soporte], #tabla-gf-rec [data-c=centro] { min-width: 120px; }
.conciliado { color: var(--color-ok); font-weight: 600; }
.gf-extracto { margin-top: var(--space-sm); }
.gf-extracto h3 { margin: var(--space-md) 0 6px; font-size: var(--text-md); }
#tabla-gf-faltan [data-concepto] { min-width: 220px; }
#tabla-gf-faltan [data-centro] { min-width: 160px; }
/* Consolidado: el total destaca y una raya lo separa del detalle por cuenta. */
#tabla-gf-cons td.gf-total { font-weight: 600; }
#tabla-gf-cons .gf-neto { border-right: 2px solid var(--color-rule-2); }
#tabla-gf tr.editando :is(input, select) { width: 100%; min-width: 5.5em; padding: var(--space-3xs) 6px; font-size: inherit;
  border-color: var(--color-rule-2); background: var(--color-paper-2); }
#tabla-gf tr.editando [name=concepto] { min-width: 14em; }
#tabla-gf tr.editando [name=fecha] { min-width: 8.5em; }
#tabla-gf tr.editando td.edita { white-space: nowrap; }
input[data-miles] { text-align: right; font-variant-numeric: tabular-nums; }

/* ================================================== bajo 60rem: barra superior */
@media (max-width: 60rem) {
  #app { padding-left: 0; }
  header {
    position: relative; inset: auto; width: auto; flex-direction: row; flex-wrap: wrap; align-items: center;
    gap: var(--space-xs) var(--space-sm); padding: var(--space-xs) var(--space-md); border-right: 0;
  }
  .marca { flex-direction: row; align-items: baseline; gap: var(--space-xs); padding: var(--space-2xs) 0; }
  .marca small, .etq-empresa, .grupo-titulo { display: none; }
  header select { flex: 1 1 90px; min-width: 0; width: auto; max-width: 260px; margin: 0; }
  .cuenta { order: 3; border-top: 0; padding-top: 0; margin-left: auto; }
  header .yo { flex: none; }
  header .yo small { display: none; }
  /* El menú baja a su propia línea y se desliza de lado; el borde que
     esconde pestañas se desvanece como aviso (app.js pone mas-izq / mas-der). */
  header nav {
    order: 5; flex: 1 0 100%; flex-direction: row; gap: var(--space-md); overflow-x: auto; overflow-y: hidden;
    border-top: 1px solid var(--color-night-rule); margin: 0 calc(var(--space-md) * -1); padding: var(--space-2xs) var(--space-md) 0;
    scrollbar-width: none; --izq: 0px; --der: 0px;
    mask-image: linear-gradient(to right, transparent, var(--color-ink) var(--izq), var(--color-ink) calc(100% - var(--der)), transparent);
  }
  header nav::-webkit-scrollbar { display: none; }
  header nav.mas-izq { --izq: 36px; }
  header nav.mas-der { --der: 36px; }
  header nav .grupo { flex-direction: row; flex: none; }
  .tab { width: auto; min-height: 44px; padding: 0 var(--space-sm); box-shadow: inset 0 -2px 0 transparent; }
  .tab .ico { display: none; }
  .tab.activo, .tab.activo:not(:disabled):hover { background: transparent; box-shadow: inset 0 -2px 0 var(--color-night-ink); }
  .tab-ayuda { width: 44px; min-height: 44px; }
}
@media (max-width: 720px) {
  body { font-size: var(--text-md); }
  section { padding: var(--space-sm); }
  .caja { padding: var(--space-md) var(--space-md) var(--space-md); }
  .caja > :is(h2, h3):first-child, .caja > .fila-titulo:first-child {
    margin: calc(var(--space-md) * -1) calc(var(--space-md) * -1) var(--space-md); padding: var(--space-sm) var(--space-md);
  }
  .procesos { grid-template-columns: 1fr; }
  .proceso { border-right: none; border-bottom: 1px solid var(--color-rule); padding: var(--space-md); }
  .proceso:last-child { border-bottom: none; }
  .param { grid-template-columns: 1fr; gap: 6px; }
  .carpetas { grid-template-columns: 1fr; }
  .arbol { flex-direction: row; flex-wrap: wrap; max-height: none; }
  .carpeta.mes { padding-left: 10px; }
  .fb-buscar { flex-basis: 100%; max-width: none; }
  .fb-der { margin-left: 0; }
  .fb-panel { grid-template-columns: 1fr 1fr; gap: 10px; padding: var(--space-sm); }
  .fb-campo:has(.fb-rango) { grid-column: 1 / -1; }
  :where(input, select) { font-size: var(--text-md); }
  .modal { padding: 0; place-items: end stretch; }
  .modal-caja { border-radius: var(--radius-card) var(--radius-card) 0 0; max-height: 92vh; padding: var(--space-lg) var(--space-md); }
  .aviso { left: var(--space-sm); right: var(--space-sm); bottom: var(--space-sm); max-width: none; }
  #lote-titulo { font-size: var(--text-lg); }
  .wiki { grid-template-columns: 1fr; }
  .wiki-indice { position: static; }
  .wiki-indice nav { flex-direction: row; flex-wrap: wrap; max-height: none; }
}
