/* Herramienta de consulta: panel de filtros a la izquierda, resultados a la derecha; en móvil se apilan. */
:root {
  --bg: #f3f5f4;
  --surface: #ffffff;
  --surface-2: #eaefed;
  --ink: #15201d;
  --muted: #5a6763;
  --line: #d6dedb;
  --accent: #0a6b5c;
  --accent-ink: #ffffff;
  --accent-soft: #dcefea;
  --warn-bg: #fdf1dc;
  --warn-ink: #7a4600;
  --err-bg: #fbe3e1;
  --err-ink: #8f1d15;
  --fil: #9a5b00;
  --fil-soft: #fbecd2;

  --f-body: "Public Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --f-mono: "JetBrains Mono", ui-monospace, Consolas, monospace;

  --r: 6px;
  --gap: 1rem;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1514; --surface: #172020; --surface-2: #1e2928; --ink: #e4ebe9; --muted: #95a39f;
    --line: #2b3735; --accent: #42c2aa; --accent-ink: #062019; --accent-soft: #163a33;
    --warn-bg: #3a2a10; --warn-ink: #f3c77c; --err-bg: #3d1714; --err-ink: #f4a39b; --fil: #f0b860; --fil-soft: #3a2a10;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1514; --surface: #172020; --surface-2: #1e2928; --ink: #e4ebe9; --muted: #95a39f;
  --line: #2b3735; --accent: #42c2aa; --accent-ink: #062019; --accent-soft: #163a33;
  --warn-bg: #3a2a10; --warn-ink: #f3c77c; --err-bg: #3d1714; --err-ink: #f4a39b; --fil: #f0b860; --fil-soft: #3a2a10;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 var(--f-body);
  padding-inline: 16px;
  padding-block: 0 2rem;
}
[hidden] { display: none !important; }

/* ---------- Encabezado ---------- */
.top {
  display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: .5rem 1rem;
  max-width: 1500px; margin: 0 auto; padding-block: 1.25rem 1rem;
  border-bottom: 1px solid var(--line);
}
.eyebrow {
  font: 500 .72rem/1 var(--f-mono); letter-spacing: .06em; text-transform: uppercase; color: var(--accent);
}
h1 { margin: .35rem 0 0; font-size: 1.6rem; font-weight: 700; letter-spacing: -.01em; text-wrap: balance; }
.top__link { color: var(--muted); font-size: .85rem; text-decoration: none; }
.top__link:hover { color: var(--accent); }

/* ---------- Layout ---------- */
.layout {
  display: grid; grid-template-columns: 380px minmax(0, 1fr); gap: 1.5rem;
  max-width: 1500px; margin: 1.25rem auto 0;
}
@media (max-width: 860px) { .layout { grid-template-columns: minmax(0, 1fr); } }

/* ---------- Panel de campos ---------- */
.panel { min-width: 0; }
@media (min-width: 861px) {
  .panel {
    position: sticky; top: env(safe-area-inset-top, 0px);
    max-height: 100vh; overflow-y: auto; overscroll-behavior: contain;
    padding-right: .4rem; margin-right: -.4rem;
  }
}
.panel form { display: flex; flex-direction: column; gap: .75rem; }

.panel__head {
  position: sticky; top: 0; z-index: 3; background: var(--bg);
  display: flex; flex-direction: column; gap: .5rem; padding-block: .25rem .6rem;
  border-bottom: 1px solid var(--line);
}
.panel__titulo { display: flex; align-items: baseline; justify-content: space-between; gap: .5rem; }
h2 { margin: 0; font-size: 1.05rem; font-weight: 700; }
.contador { font-size: .78rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.leyenda { margin: 0; font-size: .75rem; color: var(--muted); line-height: 1.7; }
.leyenda .pill { margin-right: .15rem; }
.buscador { display: flex; gap: .5rem; align-items: center; }
.buscador input { flex: 1; min-width: 0; background: var(--surface); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 4px; overflow: hidden; flex-shrink: 0; }
.seg label { margin: 0; padding: .4rem .6rem; font-size: .78rem; color: var(--muted); cursor: pointer; background: var(--surface); }
.seg label + label { border-left: 1px solid var(--line); }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label:has(input:checked) { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.seg label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: -2px; }
.mini-acciones { display: flex; flex-wrap: wrap; gap: .25rem 1rem; }

.caja { border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); padding: .6rem .8rem; }
.caja summary { cursor: pointer; font-weight: 600; font-size: .85rem; }
.caja[open] summary { margin-bottom: .5rem; }
.caja--fila { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem .6rem; }
.caja--fila label { margin: 0; color: var(--ink); font-weight: 600; font-size: .85rem; }
.caja--fila select { width: auto; flex: 1 1 120px; }
.caja--fila .hint { flex-basis: 100%; }
.ayuda-tabla { width: 100%; border-collapse: collapse; font-size: .78rem; }
.ayuda-tabla td { padding: .3rem .2rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.ayuda-tabla code { font: .74rem var(--f-mono); background: var(--surface-2); padding: .05rem .3rem; border-radius: 3px; white-space: nowrap; }
.guardadas { display: flex; flex-direction: column; gap: .5rem; }
.fila-inline { display: flex; gap: .4rem; flex-wrap: wrap; }
.fila-inline select, .fila-inline input { flex: 1 1 140px; width: auto; }

label { font-size: .8rem; color: var(--muted); margin-top: .3rem; }
label.check { display: flex; align-items: center; gap: .4rem; color: var(--ink); }
input[type="text"], input[type="search"], input[type="number"], input[type="date"], select {
  width: 100%; min-width: 0; padding: .45rem .55rem; font: inherit; color: var(--ink);
  background: var(--bg); border: 1px solid var(--line); border-radius: 4px;
}
input:focus-visible, select:focus-visible, button:focus-visible, summary:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
.hint { margin: .1rem 0 0; font-size: .75rem; color: var(--muted); }

/* Grupos y campos */
.grupos { display: flex; flex-direction: column; gap: .5rem; }
.grupo { border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); }
.grupo > summary {
  display: flex; justify-content: space-between; align-items: center; gap: .5rem;
  padding: .6rem .8rem; cursor: pointer; list-style: none;
}
.grupo > summary::-webkit-details-marker { display: none; }
.grupo > summary::before { content: "▸"; color: var(--muted); font-size: .75rem; width: .8rem; transition: transform .15s; }
.grupo[open] > summary::before { transform: rotate(90deg); }
.grupo__nom { flex: 1; font-weight: 600; font-size: .88rem; }
.grupo__cuenta { font-size: .74rem; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.grupo__cuenta.activo { color: var(--accent); font-weight: 600; }
.grupo__cuerpo { border-top: 1px solid var(--line); }
.grupo__acc { display: flex; gap: 1rem; padding: .45rem .8rem; background: var(--surface-2); }

.campo {
  display: flex; flex-direction: column; gap: .35rem;
  padding: .55rem .8rem; border-top: 1px solid var(--line);
}
.grupo__acc + .campo { border-top: 0; }
.campo.is-col, .campo.is-fil { background: color-mix(in srgb, var(--accent-soft) 45%, transparent); }
.campo__cab { display: flex; justify-content: space-between; align-items: flex-start; gap: .5rem; }
.campo__nom { display: flex; align-items: flex-start; gap: .45rem; margin: 0; color: var(--ink); font-size: .84rem; cursor: pointer; min-width: 0; }
.campo__nom input { margin: .2rem 0 0; accent-color: var(--accent); flex-shrink: 0; }
.campo__estado { display: flex; gap: .25rem; flex-shrink: 0; }
.campo__estado .pill { display: none; }
.campo.is-col .pill--col, .campo.is-fil .pill--fil { display: inline-block; }
.campo__filtro { padding-left: 1.4rem; }
.campo__filtro input { padding: .35rem .5rem; font-size: .8rem; background: var(--bg); }
.campo.is-fil .campo__filtro input { border-color: var(--fil); }
.rango { display: grid; grid-template-columns: 1fr 1fr; gap: .35rem; }
.sin-filtro { font-size: .75rem; color: var(--muted); font-style: italic; }

.acciones {
  position: sticky; bottom: 0; z-index: 3; background: var(--bg);
  display: flex; flex-direction: column; gap: .5rem; padding-block: .6rem;
  border-top: 1px solid var(--line);
}
.orden { display: grid; grid-template-columns: 1.6fr 1fr; gap: .5rem; }
.orden > div { display: flex; flex-direction: column; gap: .25rem; min-width: 0; }
.orden label { margin: 0; }

/* ---------- Botones ---------- */
.btn {
  font: 600 .85rem/1 var(--f-body); padding: .6rem .9rem; border-radius: 4px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn--primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-link {
  background: none; border: 0; padding: 0; font: 600 .8rem var(--f-body); color: var(--accent); cursor: pointer;
}
.btn-link:hover { text-decoration: underline; }

/* ---------- Resumen ---------- */
.resultados { min-width: 0; display: flex; flex-direction: column; gap: .9rem; }
.resumen {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)) minmax(0, 2fr);
  border: 1px solid var(--line); border-radius: var(--r); background: var(--surface);
}
.dato { padding: .8rem 1rem; display: flex; flex-direction: column; gap: .2rem; min-width: 0; }
.dato + .dato { border-left: 1px solid var(--line); }
.dato__k { font-size: .72rem; font-weight: 600; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); }
.dato__v { font: 600 1.15rem/1.2 var(--f-body); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.dato__desc { font-size: .82rem; color: var(--ink); }
@media (max-width: 1100px) {
  .resumen { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .dato--wide { grid-column: 1 / -1; border-left: 0 !important; border-top: 1px solid var(--line); }
}
@media (max-width: 520px) {
  .resumen { grid-template-columns: minmax(0, 1fr); }
  .dato + .dato { border-left: 0; border-top: 1px solid var(--line); }
}

/* ---------- Progreso y avisos ---------- */
.progreso { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; font-size: .85rem; color: var(--muted); }
.progreso__barra { flex: 1 1 200px; height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.progreso__barra span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .25s; }
.aviso { padding: .7rem .9rem; border-radius: var(--r); font-size: .85rem; background: var(--warn-bg); color: var(--warn-ink); }
.aviso--error { background: var(--err-bg); color: var(--err-ink); }

/* ---------- Toolbar ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; justify-content: space-between; }
.toolbar input { flex: 1 1 240px; max-width: 420px; background: var(--surface); }
.toolbar__btns { display: flex; flex-wrap: wrap; gap: .4rem; }

/* ---------- Tabla ---------- */
.tabla-wrap {
  overflow: auto; max-height: 70vh; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface);
}
table { border-collapse: collapse; width: 100%; font-size: .82rem; }
thead th {
  position: sticky; top: 0; z-index: 1; background: var(--surface-2); text-align: left; white-space: nowrap;
  padding: .55rem .7rem; font-weight: 600; font-size: .75rem; color: var(--muted); border-bottom: 1px solid var(--line);
  cursor: pointer; user-select: none;
}
thead th:hover { color: var(--ink); }
thead th[aria-sort="ascending"]::after { content: " ▲"; color: var(--accent); }
thead th[aria-sort="descending"]::after { content: " ▼"; color: var(--accent); }
td { padding: .5rem .7rem; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:hover td { background: var(--accent-soft); }
td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.fecha, td.mono { font-family: var(--f-mono); font-size: .76rem; white-space: nowrap; }
td.largo { min-width: 320px; max-width: 520px; }
td.largo div { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
td.largo div.abierto { -webkit-line-clamp: unset; }
td.vacio { padding: 2rem 1rem; color: var(--muted); text-align: center; }
td a { color: var(--accent); font-weight: 600; text-decoration: none; }
.pill {
  display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .72rem; font-weight: 600;
  background: var(--surface-2); color: var(--ink); white-space: nowrap;
}
.pill--ok { background: var(--accent-soft); color: var(--accent); }
.pill--col { background: var(--accent-soft); color: var(--accent); }
.pill--fil { background: var(--fil-soft); color: var(--fil); }
.btn--sm { padding: .45rem .7rem; font-size: .78rem; }

/* ---------- Paginación ---------- */
.paginas { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; font-size: .85rem; color: var(--muted); }
.paginas select { width: auto; }

.url-box { font-size: .8rem; color: var(--muted); }
.url-box summary { cursor: pointer; }
.url-box code {
  display: block; margin-top: .5rem; padding: .7rem; background: var(--surface); border: 1px solid var(--line);
  border-radius: 4px; font: .74rem/1.5 var(--f-mono); color: var(--ink); overflow-wrap: anywhere;
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
