:root {
  --fondo: #f6f5f1;
  --superficie: #ffffff;
  --texto: #1d2420;
  --tenue: #5d6862;
  --borde: #d9dcd6;
  --acento: #0f6b57;
  --acento-suave: #e3f0ec;
  --aviso: #8a5a00;
  --aviso-fondo: #fdf3dc;
  --error: #a3271c;
  --error-fondo: #fbe9e6;
  --marca: #fff3a8;
  --radio: 8px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fondo: #141816; --superficie: #1c211e; --texto: #e7ebe8; --tenue: #9aa6a0; --borde: #323a35;
    --acento: #5cc4a9; --acento-suave: #1f332d; --aviso: #f0c26a; --aviso-fondo: #33290f;
    --error: #ff9a8d; --error-fondo: #3a1c18; --marca: #5c4f00;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--texto); background: var(--fondo); display: flex; flex-direction: column; }
h1 { font-size: 1.35rem; margin: 0 0 .4rem; }
h2 { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--tenue); margin: 1.1rem 0 .4rem; }
code, pre, textarea#sparql { font-family: var(--mono); font-size: .86rem; }
a { color: var(--acento); }
[hidden] { display: none !important; }

.barra { display: flex; align-items: center; gap: 1.5rem; padding: .6rem 1rem; background: var(--superficie); border-bottom: 1px solid var(--borde); flex-wrap: wrap; }
.marca { display: flex; flex-direction: column; line-height: 1.2; }
.marca .sub { color: var(--tenue); font-size: .8rem; }
.pestanas { display: flex; gap: .25rem; }
.pestanas button { border: 0; background: none; color: var(--tenue); padding: .45rem .8rem; border-radius: var(--radio); font: inherit; cursor: pointer; }
.pestanas button[aria-selected="true"] { background: var(--acento-suave); color: var(--acento); font-weight: 600; }
.cobertura { margin-left: auto; font: inherit; font-size: .82rem; color: var(--tenue); background: none; border: 1px solid transparent; border-radius: var(--radio); padding: .3rem .6rem; cursor: pointer; text-align: right; }
.cobertura:hover { border-color: var(--borde); color: var(--acento); }
button.enlace { font: inherit; border: 0; background: none; padding: 0; color: var(--acento); text-decoration: underline; cursor: pointer; }

main { flex: 1; min-height: 0; display: flex; }
.vista { flex: 1; min-width: 0; display: flex; min-height: 0; }
.lateral { width: 270px; flex: none; padding: .9rem; border-right: 1px solid var(--borde); overflow-y: auto; background: var(--superficie); }
.lista { list-style: none; margin: 0; padding: 0; }
.lista li { display: flex; align-items: flex-start; gap: .3rem; }
.lista button.item { flex: 1; text-align: left; border: 0; background: none; color: inherit; font: inherit; padding: .4rem .5rem; border-radius: 6px; cursor: pointer; }
.lista button.item:hover, .lista button.item.activo { background: var(--acento-suave); }
.lista .etiqueta { display: block; font-size: .72rem; color: var(--tenue); }
.lista button.quitar { border: 0; background: none; color: var(--tenue); cursor: pointer; padding: .4rem .3rem; border-radius: 6px; }
.lista button.quitar:hover { color: var(--error); background: var(--error-fondo); }

button.primario, button.secundario { font: inherit; border-radius: var(--radio); padding: .45rem .9rem; cursor: pointer; border: 1px solid var(--acento); }
button.primario { background: var(--acento); color: #fff; }
@media (prefers-color-scheme: dark) { button.primario { color: #0d1512; } }
button.secundario { background: var(--superficie); color: var(--acento); }
button.ancho { width: 100%; }
button:disabled { opacity: .5; cursor: default; }
button:focus-visible, textarea:focus-visible, input:focus-visible { outline: 2px solid var(--acento); outline-offset: 2px; }

/* ---------- asistente ---------- */
.charla { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.mensajes { flex: 1; overflow-y: auto; padding: 1.2rem max(1rem, calc((100% - 900px) / 2)); }
.entrada { padding: .7rem max(1rem, calc((100% - 900px) / 2)) 1rem; background: var(--superficie); border-top: 1px solid var(--borde); }
.entrada textarea { width: 100%; resize: vertical; font: inherit; padding: .6rem .7rem; border: 1px solid var(--borde); border-radius: var(--radio); background: var(--fondo); color: inherit; }
.acciones { display: flex; align-items: center; gap: .7rem; margin-top: .5rem; flex-wrap: wrap; }
.acciones .uso { margin-left: auto; }
.opcion { color: var(--tenue); font-size: .88rem; display: flex; gap: .35rem; align-items: center; }
.uso { font-size: .78rem; color: var(--tenue); }

.bienvenida { max-width: 46rem; }
.bienvenida p { color: var(--tenue); }
.ideas { display: flex; flex-wrap: wrap; gap: .45rem; margin: .7rem 0 0; }
.idea { border: 1px solid var(--borde); background: var(--superficie); color: inherit; font: inherit; font-size: .9rem; padding: .4rem .7rem; border-radius: 999px; cursor: pointer; text-align: left; }
.idea:hover { border-color: var(--acento); color: var(--acento); }

.turno { margin-bottom: 1.4rem; }
.pregunta { background: var(--acento-suave); padding: .55rem .8rem; border-radius: var(--radio); margin: 0 0 .6rem auto; width: fit-content; max-width: 85%; white-space: pre-wrap; }
.respuesta { overflow-wrap: anywhere; }
.respuesta > :first-child { margin-top: 0; }
.respuesta table { border-collapse: collapse; margin: .6rem 0; font-size: .9rem; display: block; overflow-x: auto; }
.respuesta th, .respuesta td { border: 1px solid var(--borde); padding: .35rem .55rem; text-align: left; vertical-align: top; }
.respuesta th { background: var(--acento-suave); }
.respuesta pre { background: var(--superficie); border: 1px solid var(--borde); padding: .6rem; border-radius: 6px; overflow-x: auto; }
.respuesta blockquote { margin: .5rem 0; padding-left: .8rem; border-left: 3px solid var(--borde); color: var(--tenue); }
.cita { font-style: italic; }
button.ref { font: inherit; font-size: .8rem; border: 1px solid var(--acento); color: var(--acento); background: var(--superficie); border-radius: 999px; padding: 0 .5rem; cursor: pointer; white-space: nowrap; }
button.ref:hover { background: var(--acento-suave); }

.pasos { margin: 0 0 .6rem; display: flex; flex-direction: column; gap: .25rem; }
.paso { font-size: .84rem; color: var(--tenue); border: 1px solid var(--borde); border-radius: 6px; background: var(--superficie); }
.paso summary { cursor: pointer; padding: .3rem .55rem; list-style-position: inside; }
.paso.error summary { color: var(--error); }
.paso pre { margin: 0; padding: .5rem .6rem; border-top: 1px solid var(--borde); overflow-x: auto; white-space: pre-wrap; }
.paso .abrir { margin: 0 .6rem .5rem; }
.pensando::after { content: "…"; animation: puntos 1.2s steps(4, end) infinite; }
@keyframes puntos { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }
.aviso, .error-caja { padding: .5rem .7rem; border-radius: 6px; margin: .5rem 0; font-size: .9rem; }
.aviso { background: var(--aviso-fondo); color: var(--aviso); }
.error-caja { background: var(--error-fondo); color: var(--error); }
.pie-respuesta { display: flex; gap: .5rem; margin-top: .5rem; }
.pie-respuesta button { font-size: .8rem; padding: .2rem .6rem; }

.base { font-size: .8rem; color: var(--tenue); margin: .5rem 0 0; }
.base .cambio { color: var(--aviso); font-weight: 600; }

/* ---------- boletines ---------- */
.ancho-tabla { max-width: 78rem; margin: 0 auto; }
.cifras { display: flex; flex-wrap: wrap; gap: .6rem; margin: 0 0 .9rem; }
.cifra { background: var(--superficie); border: 1px solid var(--borde); border-radius: var(--radio); padding: .5rem .9rem; min-width: 8.5rem; display: flex; flex-direction: column; }
.cifra strong { font-size: 1.4rem; font-variant-numeric: tabular-nums; line-height: 1.2; }
.cifra span { font-size: .8rem; color: var(--tenue); }
.anio { background: var(--superficie); border: 1px solid var(--borde); border-radius: var(--radio); margin-top: .7rem; }
.anio summary { cursor: pointer; padding: .6rem .9rem; display: flex; gap: .9rem; align-items: baseline; flex-wrap: wrap; }
.anio summary strong { font-size: 1.05rem; }
.anio summary span { color: var(--tenue); font-size: .86rem; }
.anio .resultado { margin: 0; border-top: 1px solid var(--borde); }
.anio .resultado table { border: 0; }
.anio .resultado th, .anio .resultado td { border-width: 0 0 1px; white-space: nowrap; max-width: none; }
.anio .resultado tbody tr:last-child th, .anio .resultado tbody tr:last-child td { border-bottom: 0; }
.anio .resultado tbody th { background: none; position: static; font-weight: 600; }
.anio .resultado .etiqueta { display: block; font-weight: 400; font-size: .72rem; color: var(--tenue); }
.anio > .ayuda { margin: 0; padding: 0 .9rem .7rem; }
.acciones-fila { display: flex; gap: .8rem; align-items: baseline; }
.acciones-fila button.enlace, .acciones-fila a { font-size: .86rem; }
.situacion { display: inline-block; font-size: .78rem; padding: .05rem .5rem; border-radius: 999px; border: 1px solid var(--borde); color: var(--tenue); white-space: nowrap; }
.situacion.con-datos { background: var(--acento-suave); border-color: var(--acento); color: var(--acento); font-weight: 600; }
.situacion.basico { border-color: var(--acento); color: var(--acento); }
.situacion.descargado { background: var(--aviso-fondo); border-color: transparent; color: var(--aviso); }
.ficha.leyenda { margin: 1.3rem 0 .6rem; align-items: baseline; gap: .4rem .8rem; }

/* ---------- consultas y datos ---------- */
.trabajo { flex: 1; min-width: 0; padding: 1.2rem 1.5rem; overflow-y: auto; }
.ancho-lectura { max-width: 62rem; margin: 0 auto; }
.detalle { color: var(--tenue); margin: 0 0 .8rem; max-width: 60rem; }
.parametros { display: flex; gap: .8rem; flex-wrap: wrap; margin-bottom: .6rem; }
.parametros label { display: flex; flex-direction: column; font-size: .85rem; color: var(--tenue); gap: .2rem; }
.parametros input { font: inherit; padding: .4rem .6rem; border: 1px solid var(--borde); border-radius: 6px; background: var(--superficie); color: var(--texto); min-width: 16rem; }
details#ver-sparql { margin: .4rem 0 .6rem; }
details#ver-sparql summary { cursor: pointer; color: var(--tenue); font-size: .88rem; margin-bottom: .3rem; }
textarea#sparql { width: 100%; padding: .7rem; border: 1px solid var(--borde); border-radius: var(--radio); background: var(--superficie); color: inherit; resize: vertical; }
.ayuda { font-size: .8rem; color: var(--tenue); margin: .3rem 0 0; }
.resultado { margin-top: .8rem; overflow-x: auto; }
.resultado table { border-collapse: collapse; font-size: .86rem; width: max-content; min-width: 100%; }
.resultado th, .resultado td { border: 1px solid var(--borde); padding: .3rem .5rem; text-align: left; vertical-align: top; min-width: 5rem; max-width: 26rem; overflow-wrap: break-word; }
.resultado th { background: var(--acento-suave); position: sticky; top: 0; white-space: nowrap; }
.resultado td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.resultado pre { white-space: pre-wrap; background: var(--superficie); border: 1px solid var(--borde); padding: .7rem; border-radius: 6px; }

.bloque { background: var(--superficie); border: 1px solid var(--borde); border-radius: var(--radio); padding: .9rem 1rem; margin-bottom: .9rem; }
.bloque h3 { margin: 0 0 .3rem; font-size: 1rem; }
.bloque p { margin: .2rem 0 .5rem; color: var(--tenue); }
.formatos { display: flex; flex-wrap: wrap; gap: .4rem; }
.formatos a { font-family: var(--mono); font-size: .8rem; border: 1px solid var(--borde); border-radius: 6px; padding: .15rem .5rem; text-decoration: none; }
.formatos a:hover { border-color: var(--acento); }
.direccion { font-family: var(--mono); font-size: .86rem; background: var(--fondo); border: 1px solid var(--borde); border-radius: 6px; padding: .4rem .6rem; display: block; overflow-x: auto; white-space: pre; }

/* ---------- panel del original ---------- */
.panel { position: fixed; top: 0; right: 0; bottom: 0; width: min(46rem, 96vw); background: var(--superficie); border-left: 1px solid var(--borde); box-shadow: -8px 0 24px rgba(0, 0, 0, .18); display: flex; flex-direction: column; z-index: 10; }
.panel header { display: flex; align-items: center; gap: 1rem; padding: .7rem 1rem; border-bottom: 1px solid var(--borde); }
.panel header h2 { margin: 0; text-transform: none; letter-spacing: 0; font-size: 1rem; color: var(--texto); flex: 1; }
.panel-cuerpo { overflow-y: auto; padding: 1rem; }
.ficha { display: grid; grid-template-columns: max-content 1fr; gap: .15rem .8rem; font-size: .88rem; margin: 0 0 .8rem; }
.ficha dt { color: var(--tenue); }
.ficha dd { margin: 0; }
.recorte { border: 1px solid var(--borde); border-radius: 6px; max-width: 100%; background: #fff; display: block; margin: .3rem 0 .8rem; }
.texto-original { white-space: pre-wrap; font-size: .9rem; border: 1px solid var(--borde); border-radius: 6px; padding: .8rem; background: var(--fondo); }
mark { background: var(--marca); color: inherit; padding: 0 .1em; border-radius: 2px; }
.enlaces { display: flex; flex-wrap: wrap; gap: .5rem; margin: .6rem 0; font-size: .88rem; }

@media (max-width: 760px) {
  .lateral { display: none; }
  .barra { gap: .6rem; }
}

/* historial de conversaciones */
.lateral .filtro { width: 100%; box-sizing: border-box; font: inherit; font-size: .85rem; padding: .35rem .5rem; margin: 0 0 .4rem; border: 1px solid var(--borde); border-radius: var(--radio); background: var(--superficie); color: inherit; }
.lista .acciones-item { display: flex; flex-direction: column; gap: .1rem; }
.lista button.quitar, .lista button.bajar { font-size: .8rem; line-height: 1; }
.lista button.bajar { border: 0; background: none; color: var(--tenue); cursor: pointer; padding: .4rem .3rem; border-radius: 6px; }
.lista button.bajar:hover { color: var(--acento); background: var(--acento-suave); }
.lista .marca { display: inline-block; font-size: .68rem; padding: 0 .35rem; margin-left: .3rem; border-radius: 999px; border: 1px solid var(--borde); color: var(--tenue); vertical-align: middle; }
.gestion-historial { display: flex; flex-direction: column; align-items: flex-start; gap: .2rem; margin-top: .6rem; font-size: .8rem; }
.gestion-historial .peligro { color: var(--error); }
/* bienvenida: preguntas por perfil y consejos */
.bienvenida .grupo h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--tenue); margin: 1rem 0 0; }
.bienvenida .consejos { margin: .4rem 0 0; padding-left: 1.1rem; color: var(--tenue); font-size: .88rem; }
.bienvenida .consejos li { margin: .2rem 0; }
