:root {
  --fondo: #f4f3ef; --papel: #ffffff; --tinta: #1d2420; --suave: #5f6b64; --linea: #e2e0d8;
  --verde: #1f4d3a; --verde-2: #2f6b52; --rojo: #c0392b; --ambar: #b7791f; --azul: #2563a8; --ok: #2e7d4f;
  --chip-pend: #eef0f2; --chip-antic: #e4eefb; --chip-pago: #fff3d6; --chip-liq: #e1f3e8; --chip-venc: #fbe3e0;
  --sombra: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --fondo: #141816; --papel: #1c211e; --tinta: #e8ece9; --suave: #9aa59f; --linea: #2c332f;
    --verde: #6fbf95; --verde-2: #8fd1ad; --rojo: #ef7b6c; --ambar: #e2b04a; --azul: #7fb0ea; --ok: #7fcf9d;
    --chip-pend: #262c29; --chip-antic: #1d2b3d; --chip-pago: #3a321c; --chip-liq: #1d3327; --chip-venc: #3d2220;
    --sombra: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --fondo: #141816; --papel: #1c211e; --tinta: #e8ece9; --suave: #9aa59f; --linea: #2c332f;
  --verde: #6fbf95; --verde-2: #8fd1ad; --rojo: #ef7b6c; --ambar: #e2b04a; --azul: #7fb0ea; --ok: #7fcf9d;
  --chip-pend: #262c29; --chip-antic: #1d2b3d; --chip-pago: #3a321c; --chip-liq: #1d3327; --chip-venc: #3d2220;
  --sombra: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--fondo); color: var(--tinta); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--azul); }
h1 { font-size: 1.5rem; margin: 0 0 .75rem; letter-spacing: -.01em; }
h2 { font-size: 1.02rem; margin: 0 0 .75rem; }
h3 { font-size: .95rem; margin: 1rem 0 .5rem; color: var(--suave); }
[hidden], .oculto { display: none !important; }
code { background: var(--chip-pend); padding: 1px 5px; border-radius: 4px; word-break: break-all; }

/* Barra */
#barra { position: sticky; top: 0; z-index: 5; display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1.25rem;
  padding: .6rem 16px; background: var(--papel); border-bottom: 1px solid var(--linea); }
.marca { display: flex; align-items: center; gap: .5rem; font-size: 1.05rem; }
.marca img { width: 28px; height: 28px; }
#menu { display: flex; gap: .25rem; flex-wrap: wrap; }
#menu a { text-decoration: none; color: var(--suave); padding: .35rem .7rem; border-radius: 8px; font-weight: 500; }
#menu a.activo, #menu a:hover { background: var(--chip-pend); color: var(--tinta); }
.derecha { margin-left: auto; display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; color: var(--suave); font-size: .85rem; }

main { max-width: 1400px; margin: 0 auto; padding: 20px 16px 60px; }
.pantalla.centro { min-height: 80vh; display: grid; place-items: center; }

/* Login */
.caja-login { background: var(--papel); border: 1px solid var(--linea); border-radius: 16px; padding: 28px; width: min(380px, 100%);
  box-shadow: var(--sombra); display: flex; flex-direction: column; gap: .8rem; }
.caja-login.ancha { width: min(460px, 100%); }
.caja-login .logo { width: 52px; height: 52px; }
.caja-login .sub { margin: -.4rem 0 .3rem; color: var(--suave); }
.qr { width: 200px; height: 200px; align-self: center; background: #fff; padding: 8px; border-radius: 8px; }
.pasos { margin: 0; padding-left: 1.2rem; }

/* Formularios */
label { display: flex; flex-direction: column; gap: .25rem; font-size: .82rem; color: var(--suave); font-weight: 500; }
input, select, textarea { font: inherit; font-size: .93rem; color: var(--tinta); background: var(--papel); border: 1px solid var(--linea);
  border-radius: 8px; padding: .45rem .6rem; min-width: 0; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--verde-2); outline-offset: 0; border-color: transparent; }
input:disabled, select:disabled, textarea:disabled { background: var(--fondo); color: var(--suave); }
input.falta { border-color: var(--ambar); }
label.check { flex-direction: row; align-items: center; gap: .5rem; color: var(--tinta); }
label.check input { width: auto; }
.btn { font: inherit; font-weight: 600; border: 0; border-radius: 9px; padding: .55rem 1rem; background: var(--verde); color: #fff; cursor: pointer; }
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .55; cursor: wait; }
.btn.sec { background: var(--chip-pend); color: var(--tinta); }
.btn.peligro { background: transparent; color: var(--rojo); border: 1px solid currentColor; }
.btn.chico { padding: .3rem .7rem; font-size: .85rem; }
.acciones { display: flex; gap: .5rem; align-items: end; }

.filtros { display: flex; flex-wrap: wrap; gap: .6rem; align-items: end; margin-bottom: 1rem; padding: .8rem; background: var(--papel);
  border: 1px solid var(--linea); border-radius: 12px; }
.filtros label { flex: 1 1 140px; }
.filtros label.crece { flex: 2 1 220px; }

.rejilla { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: .7rem 1rem; }
.rejilla .ancho { grid-column: 1 / -1; }
.fila-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: .6rem .9rem; align-items: end; }
.fila-form .ancho { grid-column: 1 / -1; }
.fila-form .ancho2 { grid-column: span 2; }
.fila-form.compacta { padding: .55rem 0; border-bottom: 1px dashed var(--linea); }
.fila-form.compacta:last-child { border-bottom: 0; }
.selector { flex-direction: row; align-items: center; gap: .6rem; max-width: 360px; margin-bottom: .5rem; font-size: .95rem; }

/* Tarjetas y KPIs */
.tarjeta { background: var(--papel); border: 1px solid var(--linea); border-radius: 14px; padding: 16px; margin-bottom: 1rem; box-shadow: var(--sombra); }
.tarjeta.nueva { border-style: dashed; }
.tarjeta.nueva h3 { margin-top: 0; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.kpi { background: var(--papel); border: 1px solid var(--linea); border-radius: 14px; padding: 14px; display: flex; flex-direction: column; gap: .15rem; box-shadow: var(--sombra); }
.kpi span { font-size: .8rem; color: var(--suave); font-weight: 600; }
.kpi strong { font-size: 1.35rem; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.kpi small { color: var(--suave); font-size: .78rem; min-height: 1em; }
.kpi.bueno strong { color: var(--ok); }
.kpi.malo strong { color: var(--rojo); }
.kpi.alerta { border-color: var(--rojo); }
.dos { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(460px, 100%), 1fr)); gap: 1rem; }
.titulo-fila { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.titulo-fila h1 { display: flex; align-items: center; gap: .6rem; }
.sub { color: var(--suave); margin-top: -.3rem; }

/* Tablas */
.tabla-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; font-variant-numeric: tabular-nums; }
th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .03em; color: var(--suave); font-weight: 600;
  padding: .5rem .55rem; border-bottom: 1px solid var(--linea); white-space: nowrap; }
td { padding: .5rem .55rem; border-bottom: 1px solid var(--linea); vertical-align: top; }
td small { color: var(--suave); }
.n { text-align: right; white-space: nowrap; }
tfoot td { font-weight: 700; border-bottom: 0; }
tr.clic { cursor: pointer; }
tr.clic:hover td { background: var(--fondo); }
tr.tenue td { opacity: .5; }
td input.precio { width: 92px; text-align: right; padding: .25rem .4rem; }
td.detalle { font-size: .8rem; color: var(--suave); word-break: break-word; max-width: 520px; }
.vacio { color: var(--suave); text-align: center; padding: 1rem; }

.cascada td { padding: .45rem .3rem; }
.cascada tr.sep td { border-bottom: 2px solid var(--linea); }
.cascada tr.total td { font-size: 1.05rem; font-weight: 800; border-bottom: 0; border-top: 2px solid var(--tinta); }
.pos { color: var(--ok); }
.neg { color: var(--rojo); }
.real, .estim { font-size: .7rem; font-weight: 700; padding: 1px 6px; border-radius: 99px; }
.real { background: var(--chip-liq); color: var(--ok); }
.estim { background: var(--chip-pend); color: var(--suave); }

.chip { display: inline-block; font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 99px; white-space: nowrap; background: var(--chip-pend); color: var(--tinta); }
.chip.antic { background: var(--chip-antic); color: var(--azul); }
.chip.pago { background: var(--chip-pago); color: var(--ambar); }
.chip.liq { background: var(--chip-liq); color: var(--ok); }
.chip.vencido { background: var(--chip-venc); color: var(--rojo); }
.chip.excl { opacity: .6; }
.ico-aviso { color: var(--ambar); cursor: help; }

.linea-tiempo { list-style: none; margin: 0; padding: 0 0 0 1.2rem; border-left: 2px solid var(--linea); }
.linea-tiempo li { position: relative; padding: .2rem 0 .9rem .6rem; color: var(--suave); }
.linea-tiempo li::before { content: ""; position: absolute; left: -1.62rem; top: .45rem; width: 12px; height: 12px; border-radius: 50%; background: var(--papel); border: 2px solid var(--linea); }
.linea-tiempo li.hecho { color: var(--tinta); }
.linea-tiempo li.hecho::before { background: var(--ok); border-color: var(--ok); }
.linea-tiempo li.tarde::before { background: var(--rojo); border-color: var(--rojo); }
.linea-tiempo b { display: block; color: var(--tinta); }

/* Barras de flujo */
.barras { display: flex; flex-direction: column; gap: .4rem; }
.barra-fila { display: grid; grid-template-columns: 110px 1fr 110px; gap: .6rem; align-items: center; font-size: .82rem; }
.barra-fila .et { color: var(--suave); }
.pista { display: flex; height: 14px; background: var(--fondo); border-radius: 4px; overflow: hidden; }
.pista i { display: block; height: 100%; width: 0; }
.pista i.a, .leyenda i.a { background: var(--azul); }
.pista i.r, .leyenda i.r { background: var(--verde-2); }
.leyenda { font-size: .78rem; color: var(--suave); display: flex; align-items: center; gap: .35rem; }
.leyenda i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-left: .6rem; }

.pestanas { display: flex; gap: .3rem; border-bottom: 1px solid var(--linea); margin-bottom: 1rem; overflow-x: auto; }
.pestanas button { font: inherit; font-weight: 600; background: none; border: 0; padding: .6rem 1rem; color: var(--suave); border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap; }
.pestanas button.activo { color: var(--tinta); border-bottom-color: var(--verde); }

.nota { color: var(--suave); font-size: .85rem; }
.nota-caja { background: var(--chip-pago); border-radius: 10px; padding: .7rem .9rem; margin-bottom: 1rem; font-size: .9rem; }
.cargando { position: fixed; top: 64px; left: 50%; transform: translateX(-50%); background: var(--tinta); color: var(--papel); padding: .4rem 1rem; border-radius: 99px; font-size: .85rem; z-index: 10; }
.aviso { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); max-width: calc(100% - 32px); padding: .7rem 1.1rem; border-radius: 10px;
  background: var(--tinta); color: var(--papel); box-shadow: 0 6px 24px rgba(0,0,0,.2); z-index: 20; font-weight: 500; }
.aviso.ok { background: var(--ok); color: #fff; }
.aviso.error { background: var(--rojo); color: #fff; }

@media (max-width: 640px) {
  .derecha { margin-left: 0; width: 100%; }
  .fila-form .ancho2 { grid-column: 1 / -1; }
  .barra-fila { grid-template-columns: 80px 1fr 90px; }
  .kpi strong { font-size: 1.15rem; }
}
