/* ==========================================================================
   listado.css — página "Listado de instituciones" (directorio completo)
   Requiere base.css + site.css. Todo prefijado con .page-listado / .listado-*.
   Móvil primero: < 768 la tabla se convierte en tarjetas; ≥ 1024 thead sticky bajo el header.
   ========================================================================== */

/* ---------- Cabecera de página ---------- */
.listado-hero { padding-bottom: clamp(2.25rem, 5vw, 3.25rem); }
.listado-hero .page-hero__content { max-width: 54rem; }
.listado-hero .lead { max-width: 56ch; }
.listado-hero .lead strong { color: var(--text); font-weight: 700; }

/* Banda de cifras: hilos finos, sin caja; el número manda */
.listado-kpis {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: clamp(2.25rem, 5vw, 3.5rem) 0 0;
  border-top: 1px solid var(--border-strong);
}
.listado-kpi {
  display: grid; align-content: start; gap: .35rem;
  padding: clamp(1rem, 2.4vw, 1.5rem) clamp(.75rem, 2vw, 1.5rem) clamp(1rem, 2.4vw, 1.5rem) 0;
  border-bottom: 1px solid var(--border);
}
.listado-kpi:nth-child(even) { padding-left: clamp(1rem, 3vw, 1.75rem); border-left: 1px solid var(--border); }
.listado-kpi dt {
  order: 2; font-size: var(--fs-xs); font-weight: 700; letter-spacing: .1em;
  text-transform: uppercase; color: var(--text-muted); text-wrap: balance;
}
.listado-kpi dd {
  order: 1; margin: 0; font-family: var(--font-display); font-weight: 600;
  font-size: clamp(2.25rem, 1.5rem + 2.4vw, 3.25rem); line-height: .95; letter-spacing: -.035em;
  color: var(--primary-strong); font-variant-numeric: tabular-nums;
}
@media (min-width: 720px) {
  .listado-kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .listado-kpi { border-bottom: 0; }
  .listado-kpi + .listado-kpi { padding-left: clamp(1rem, 2.5vw, 2rem); border-left: 1px solid var(--border); }
}
.listado-fuente { margin-top: var(--sp-4); font-size: var(--fs-xs); color: var(--text-muted); }

/* ---------- Sección principal ---------- */
/* El h1 del hero es el título de la página: el h2 de la sección entra un escalón más abajo */
.listado-main .section__head { margin-bottom: clamp(1.5rem, 3vw, 2.25rem); align-items: baseline; }
.listado-main .section__head h2 { font-size: clamp(1.625rem, 1.25rem + 1.4vw, 2.25rem); }
.listado-main .section__head .lead { font-size: 1.0625rem; max-width: 54ch; }
.listado-main .section__head--split .link-arrow { margin-bottom: 0; }

/* ---------- Panel de filtros ---------- */
.listado-filtros {
  display: grid; gap: var(--sp-6);
  padding: clamp(1.125rem, 3vw, 1.75rem);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  scroll-margin-top: calc(var(--header-h) + 1rem);
}
.listado-filtros__row { display: grid; gap: var(--sp-4); align-items: end; }
.listado-filtros__group { display: grid; gap: .45rem; align-content: end; min-width: 0; }
.listado-filtros__label {
  font-size: var(--fs-xs); font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: var(--text-muted);
}
.listado-filtros .form-field__label { margin-bottom: 0; }
.listado-filtros .form-field select, .listado-filtros .input { background: var(--bg); }
.listado-filtros .form-field { display: grid; gap: .45rem; }
.listado-filtros__search .input { height: 3.25rem; font-size: 1.0625rem; }
.listado-filtros__search .search__icon { left: 1.125rem; }
.listado-filtros__segmented { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.listado-filtros__segmented > * { min-height: 2.75rem; padding-inline: .35rem; }
.listado-filtros__switches { display: flex; flex-wrap: wrap; gap: .25rem 2rem; align-items: center; }
.listado-filtros__row--bottom { gap: var(--sp-3) var(--sp-6); padding-top: var(--sp-4); border-top: 1px solid var(--border); }
.listado-filtros__limpiar { justify-self: start; }

/* Chips de tipo: superficie limpia, el color del tipo vive en el borde y en el estado activo */
.listado-chips { position: relative; gap: .45rem; }
.page-listado .listado-chips .chip--tipo {
  background: var(--bg);
  border-color: color-mix(in srgb, var(--c) 38%, var(--border));
  color: var(--text);
}
.page-listado .listado-chips .chip--tipo:hover {
  background: color-mix(in srgb, var(--c) 8%, var(--bg));
  border-color: color-mix(in srgb, var(--c) 70%, var(--border));
}
.page-listado .listado-chips .chip--tipo[aria-pressed="true"] {
  background: var(--c); border-color: var(--c); color: #fff;
  box-shadow: 0 6px 16px -10px var(--c);
}
.listado-chips .chip__count { background: color-mix(in srgb, currentColor 10%, transparent); }
.listado-chips .chip.is-zero { opacity: .5; }
.listado-chips .chip.is-zero[aria-pressed="true"] { opacity: 1; }
@media (max-width: 899px) {
  .listado-chips { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding: 2px 0 .35rem; margin-inline: calc(-1 * clamp(1.125rem, 3vw, 1.75rem)); padding-inline: clamp(1.125rem, 3vw, 1.75rem); scroll-padding-inline: clamp(1.125rem, 3vw, 1.75rem); -webkit-overflow-scrolling: touch; scroll-snap-type: x proximity; }
  .listado-chips::-webkit-scrollbar { display: none; }
  .listado-chips .chip { flex: none; scroll-snap-align: start; }
}
@media (max-width: 419px) {
  .listado-filtros__segmented > * { padding-inline: .15rem; font-size: var(--fs-xs); }
}
@media (min-width: 600px) {
  .listado-filtros__row--selects { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .listado-filtros__part { grid-column: 1 / -1; }
  .listado-filtros__row--bottom { grid-template-columns: 1fr auto; align-items: center; }
  .listado-filtros__limpiar { justify-self: end; }
}
@media (min-width: 960px) {
  .listado-filtros__row--selects { grid-template-columns: auto minmax(12rem, 1fr) minmax(13rem, 1fr); }
  .listado-filtros__part { grid-column: auto; }
  .listado-filtros__segmented { grid-template-columns: repeat(4, minmax(5.5rem, auto)); }
}

/* ---------- Barra de estado y acciones ---------- */
.listado-toolbar {
  display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between;
  gap: var(--sp-3) var(--sp-6); margin-block: var(--sp-8) var(--sp-4);
  padding-bottom: var(--sp-4); border-bottom: 1px solid var(--border);
}
.listado-toolbar__status { display: grid; gap: .2rem; min-width: 0; }
.listado-count { font-size: 1rem; color: var(--text-muted); }
.listado-count strong {
  font-family: var(--font-display); font-weight: 600; font-size: clamp(1.5rem, 1.2rem + .9vw, 2rem);
  line-height: 1; color: var(--text); letter-spacing: -.025em; margin-right: .2rem;
}
.listado-activos { overflow-wrap: anywhere; }
.listado-toolbar__actions { display: flex; flex-wrap: wrap; gap: .375rem; }

/* ---------- Tabla (≥ 768) ---------- */
.listado-table { table-layout: fixed; min-width: 64rem; }
.listado-table thead th {
  padding-inline: .625rem; letter-spacing: .05em;
  border-bottom: 1px solid var(--border-strong);
}
.listado-table thead th:first-child { padding-left: 1rem; }
.listado-table thead th:last-child { padding-right: 1rem; }
.listado-table th.c-toggle { width: 2.75rem; }
.listado-table th.c-tipo { width: 12rem; }
.listado-table th.c-fund { width: 7.25rem; }
.listado-table th.c-partido { width: 6rem; }
.listado-table th.c-loc { width: 9rem; }
.listado-table th.c-bib { width: 6.75rem; }
.listado-table th.c-acc { width: 7rem; }
.listado-table td, .listado-table th { vertical-align: middle; }
.listado-table td, .listado-table th[scope="row"] { padding: .7rem .625rem; }
.listado-table td.c-toggle { padding: .25rem 0 .25rem .375rem; }
.listado-table th.c-nombre, .listado-table td.c-nombre { text-align: left; }
.listado-table th[scope="row"] { font-weight: 600; color: var(--text); font-size: 1rem; padding-left: .5rem; }
.listado-table td.c-acc { padding-inline: .25rem .75rem; text-align: right; }
.listado-table .num { font-variant-numeric: tabular-nums; }
.listado-nombre { display: block; line-height: 1.3; text-wrap: pretty; }
.listado-table td.c-tipo { color: var(--text); }
.listado-tipo { display: inline-flex; align-items: center; gap: .4rem; min-width: 0; }
.listado-tipo .emoji { font-size: 1.05em; flex: none; }
/* La jerarquía de la tabla: el nombre a 1rem, todo lo demás un escalón abajo */
.listado-table td.c-tipo, .listado-table td.c-fund, .listado-table td.c-partido,
.listado-table td.c-loc, .listado-table td.c-bib { font-size: var(--fs-xs); }
.listado-table td.c-fund { color: var(--text-muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.listado-table td.c-partido, .listado-table td.c-loc, .listado-table td.c-bib { color: var(--text-muted); }
.listado-nd { color: var(--text-muted); opacity: .65; }
.listado-campo {
  display: inline-flex; align-items: center; gap: .3rem; margin-top: .3rem;
  font-size: var(--fs-xs); font-weight: 600; color: var(--text-muted);
  border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); padding: .05rem .4rem;
}
.listado-bib-si { display: inline-flex; align-items: center; gap: .3rem; font-weight: 700; color: var(--success); }
.listado-bib-si svg { width: .9375rem; height: .9375rem; flex: none; }
.listado-cargando td { text-align: center; color: var(--text-muted); padding-block: var(--sp-8); }
.listado-row { cursor: pointer; }
.listado-row a, .listado-row button { cursor: pointer; }
.listado-table tbody tr.listado-row:hover { background: var(--surface); box-shadow: inset 3px 0 0 var(--c); }
.listado-row.is-open { background: var(--surface); box-shadow: inset 4px 0 0 var(--c); }
.listado-row.is-open td, .listado-row.is-open th { border-bottom-color: transparent; }


/* Botón desplegar */
.listado-toggle {
  display: grid; place-items: center; width: 2.5rem; height: 2.5rem; border-radius: 50%;
  color: var(--text-muted); background: transparent; border: 1px solid transparent;
  transition: background-color var(--dur-fast), color var(--dur-fast), border-color var(--dur-fast);
}
.listado-toggle svg { width: 1.0625rem; height: 1.0625rem; transition: transform var(--dur-base) var(--ease-out); }
.listado-row:hover .listado-toggle { color: var(--text); }
.listado-toggle:hover { background: var(--bg); border-color: var(--border); color: var(--text); }
.listado-toggle[aria-expanded="true"] { background: var(--primary-soft-2); border-color: transparent; color: var(--primary-strong); }
.listado-toggle[aria-expanded="true"] svg { transform: rotate(180deg); }

/* Acción "Ver en mapa": enlace discreto que se enciende con la fila */
.listado-ir {
  display: inline-flex; align-items: center; justify-content: flex-end; gap: .35rem;
  min-width: 2.75rem; min-height: 2.75rem; padding: .5rem .5rem .5rem .375rem;
  border-radius: var(--radius-sm); color: var(--text-muted); font-weight: 700;
  font-size: var(--fs-xs); text-decoration: none; white-space: nowrap;
  transition: color var(--dur-fast), background-color var(--dur-fast);
}
.listado-ir svg { width: 1.0625rem; height: 1.0625rem; flex: none; }
.listado-row:hover .listado-ir { color: var(--primary); }
.listado-ir:hover, .listado-ir:focus-visible { color: var(--primary-strong); background: var(--primary-soft); }
.listado-row.is-open .listado-ir { color: var(--primary); }

/* Franja 1024–1199: la tabla ya no hace scroll, hay que ceder ancho a la columna Nombre */
@media (min-width: 1024px) and (max-width: 1199px) {
  .listado-table th.c-tipo { width: 10rem; }
  .listado-table th.c-loc { width: 8rem; }
  .listado-table th.c-acc { width: 3.25rem; }
  .listado-ir span { display: none; }
}

/* Fila de detalle */
.listado-detalle > td { padding: 0; background: var(--surface); }
.listado-ficha {
  position: relative; display: grid; gap: var(--sp-4);
  padding: clamp(1rem, 3vw, 1.75rem) clamp(1rem, 3vw, 1.75rem) clamp(1.25rem, 3vw, 1.75rem);
  border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
  box-shadow: inset 4px 0 0 var(--c, var(--primary));
  animation: listado-in var(--dur-base) var(--ease-out);
}
@keyframes listado-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .listado-ficha { animation: none; } }
@media (min-width: 900px) {
  .listado-ficha { grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); column-gap: var(--sp-8); padding-left: clamp(1.5rem, 4vw, 3.25rem); }
  .listado-ficha .ficha__head, .listado-ficha .ficha__badges, .listado-ficha .ficha__acciones { grid-column: 1 / -1; }
  .listado-ficha .ficha__sedes { grid-column: 2; grid-row: 3; }
  .listado-ficha .ficha__datos { grid-column: 1; }
  .listado-ficha:not(:has(.ficha__sedes)) .ficha__datos { grid-column: 1 / -1; }
}

/* ---------- Ficha (markup de FED.core.fichaHTML) ---------- */
.listado-ficha .ficha__head { display: flex; gap: var(--sp-4); align-items: flex-start; }
.listado-ficha .ficha__head .pin { margin-top: -.25rem; }
.listado-ficha .ficha__titulo { display: grid; gap: .25rem; min-width: 0; }
.listado-ficha .ficha__nombre { font-family: var(--font-display); font-weight: 600; font-size: clamp(1.25rem, 1.05rem + .8vw, 1.625rem); line-height: 1.15; letter-spacing: -.01em; text-wrap: balance; }
.listado-ficha .ficha__kicker { font-size: var(--fs-small); color: var(--text-muted); }
.listado-ficha .ficha__badges { display: flex; flex-wrap: wrap; gap: .375rem; }
.listado-ficha .ficha__badges .badge { white-space: normal; }
.listado-ficha .ficha__datos { display: grid; gap: var(--sp-3) var(--sp-6); margin: 0; align-content: start; }
@media (min-width: 600px) { .listado-ficha .ficha__datos { grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); } }
.listado-ficha .ficha__dato { display: grid; gap: .2rem; padding: .75rem .875rem; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); min-width: 0; }
.listado-ficha .ficha__dato dt { font-size: var(--fs-xs); font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--text-muted); }
.listado-ficha .ficha__dato dd { margin: 0; font-weight: 600; font-size: .9375rem; overflow-wrap: anywhere; }
.listado-ficha .ficha__dato dd a { color: var(--primary); text-decoration: none; }
.listado-ficha .ficha__dato dd a:hover { text-decoration: underline; }
.listado-ficha .ficha__sin-dato { font-weight: 500; color: var(--text-muted); font-style: italic; }
.listado-ficha .ficha__sedes { display: grid; gap: .5rem; align-content: start; padding: .875rem 1rem; background: var(--bg); border: 1px dashed var(--border-strong); border-radius: var(--radius); }
.listado-ficha .ficha__subtitulo { font-family: var(--font-body); font-size: var(--fs-xs); font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--text-muted); }
.listado-ficha .ficha__lista { display: grid; gap: .5rem; }
.listado-ficha .ficha__sede { display: flex; flex-wrap: wrap; align-items: baseline; gap: .15rem .5rem; font-size: var(--fs-small); }
.listado-ficha .ficha__sede-rol { font-weight: 700; color: var(--text); }
.listado-ficha .ficha__sede-dir { flex-basis: 100%; color: var(--text-muted); font-size: var(--fs-xs); }
.listado-ficha .ficha__sede-ir { font-weight: 700; font-size: var(--fs-xs); }
.listado-ficha .ficha__acciones { display: flex; flex-wrap: wrap; gap: .5rem; padding-top: .25rem; }

/* ---------- Cargar más / vacío ---------- */
.listado-mas { display: grid; justify-items: center; gap: var(--sp-3); margin-top: var(--sp-8); text-align: center; }
.listado-mas__info { font-size: var(--fs-small); color: var(--text-muted); font-variant-numeric: tabular-nums; }
.listado-empty { display: grid; justify-items: center; gap: .75rem; margin-top: var(--sp-6); padding-block: var(--sp-12); }
.listado-empty p { max-width: 34ch; }

/* ---------- Escritorio ≥ 1024: thead pegado bajo el header ---------- */
@media (min-width: 1024px) {
  .page-listado .listado-wrap { overflow: visible; }
  .listado-table { min-width: 0; }
  .page-listado .listado-table thead th { top: var(--header-h); box-shadow: 0 1px 0 var(--border-strong); }
}

/* ---------- Móvil < 768: filas → tarjetas ---------- */
@media (max-width: 767px) {
  .page-listado .listado-wrap { overflow: visible; border: 0; border-radius: 0; background: transparent; }
  .listado-table, .listado-table tbody, .listado-table tr, .listado-table td, .listado-table th, .listado-table caption { display: block; }
  .listado-table { min-width: 0; }
  .listado-table thead { display: none; }
  .listado-table tbody { display: grid; gap: .625rem; }
  .listado-table td, .listado-table th { padding: 0; border: 0; }
  .listado-table tr.listado-row {
    position: relative; display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas: "nombre nombre" "tipo tipo" "partido loc" "fund fund" "bib bib" "acc acc";
    gap: .2rem .4rem; align-items: baseline;
    padding: .875rem 3.25rem .875rem 1rem;
    background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-lg);
    box-shadow: inset 3px 0 0 var(--c);
  }
  .listado-table tbody tr.listado-row:hover { background: var(--bg); }
  .listado-row.is-open { border-bottom-left-radius: 0; border-bottom-right-radius: 0; background: var(--bg); box-shadow: inset 3px 0 0 var(--c); }
  .listado-row .c-toggle { position: absolute; top: .5rem; right: .5rem; grid-area: auto; }
  .listado-row .c-nombre { grid-area: nombre; font-size: 1.0625rem; font-weight: 700; line-height: 1.3; padding: 0 0 .2rem; }
  .listado-row .c-tipo { grid-area: tipo; }
  .listado-row .c-partido { grid-area: partido; font-size: var(--fs-small); white-space: nowrap; }
  .listado-row .c-loc { grid-area: loc; font-size: var(--fs-small); }
  .listado-row .c-loc::before { content: "· "; color: var(--text-muted); }
  .listado-row .c-loc.is-empty { display: none; }
  .listado-row .c-fund { grid-area: fund; font-size: var(--fs-small); text-align: left; white-space: nowrap; }
  .listado-row .c-fund::before { content: attr(data-label) " "; color: var(--text-muted); }
  .listado-row .c-bib { grid-area: bib; font-size: var(--fs-small); }
  .listado-row .c-bib::before { content: attr(data-label) ": "; color: var(--text-muted); }
  .listado-row .c-bib.is-empty { display: none; }
  .listado-row .c-fund.is-empty { color: var(--text-muted); }
  .listado-table td.c-acc { grid-area: acc; text-align: left; padding: .45rem 0 0; }
  .listado-ir { justify-content: flex-start; min-height: 2.5rem; padding-inline: 0 .5rem; color: var(--primary); font-size: var(--fs-small); }
  .listado-ir:hover, .listado-ir:focus-visible { background: transparent; }
  .listado-detalle { display: block; margin-top: -.625rem; }
  .listado-detalle > td { display: block; padding: 0; }
  .listado-ficha { border: 1px solid var(--border); border-top: 0; border-radius: 0 0 var(--radius-lg) var(--radius-lg); background: var(--surface); }
  .listado-toolbar { align-items: flex-start; }
}

/* ---------- Encabezado de impresión (oculto en pantalla) ---------- */
.listado-print { display: none; }

/* ---------- Impresión ---------- */
@media print {
  .page-listado { --bg: #fff; --surface: #f2f2f2; --surface-2: #e8e8e8; --text: #000; --text-muted: #333; --border: #bbb; --border-strong: #999; --primary: #000; --primary-strong: #000; }
  .page-listado .listado-hero, .page-listado .listado-filtros, .page-listado .listado-toolbar, .page-listado .listado-cta, .page-listado .section__head, .page-listado .listado-mas, .page-listado .listado-empty[hidden] { display: none !important; }
  .page-listado .listado-main { padding-block: 0; }
  .listado-print { display: block; margin-bottom: 8pt; }
  .listado-print__title { font-family: var(--font-display); font-weight: 600; font-size: 15pt; color: #000; margin-bottom: 3pt; }
  .listado-print__meta { font-size: 9pt; color: #333; }
  .page-listado .listado-wrap { overflow: visible; border: 0; border-radius: 0; background: #fff; }
  .page-listado .listado-table, .page-listado .listado-table tbody, .page-listado .listado-table tr, .page-listado .listado-table td, .page-listado .listado-table th { display: revert; }
  .page-listado .listado-table { font-size: 9pt; min-width: 0; }
  .page-listado .listado-table thead { display: table-header-group; }
  .page-listado .listado-table thead th { position: static; background: #eee; color: #000; box-shadow: none; padding: 4pt 6pt; border-bottom: 1px solid #999; }
  .page-listado .listado-table thead th button::after { display: none; }
  .page-listado .listado-table td, .page-listado .listado-table th[scope="row"] { padding: 4pt 6pt; border-bottom: 1px solid #ddd; color: #000; vertical-align: top; font-size: 9pt; }
  .page-listado .listado-table tr { break-inside: avoid; }
  .page-listado .listado-row { box-shadow: none; background: #fff; }
  .page-listado .listado-row .c-fund::before, .page-listado .listado-row .c-bib::before, .page-listado .listado-row .c-loc::before { content: ""; }
  .page-listado .listado-table .c-toggle, .page-listado .listado-table .c-acc { display: none; }
  .page-listado .listado-detalle { display: none; }
  .page-listado .listado-campo { border-color: #999; color: #333; }
  .page-listado .listado-bib-si { color: #000; }
  .page-listado .listado-bib-si svg { display: none; }
  .page-listado .listado-nd { color: #666; }
}

/* El carril de chips sangra a los bordes con margen negativo: sin este recorte, su contenido
   desplazable hace que la página entera se pueda mover de costado entre 768 y 899 px. */
@media (max-width: 899px) {
  .page-listado .listado-main { overflow-x: clip; }
}
