:root {
    --fondo: #f4f6f9;
    --superficie: #ffffff;
    --texto: #2b2b2b;
    --texto-suave: #5f6b76;
    --borde: #dcdfe3;
    --cabecera: #2c3e50;
    --primario: #27ae60;
    --primario-hover: #219653;
    --secundario: #0288d1;
    --peligro: #d84343;
    --aviso: #ffca28;
    --exito-fondo: #e8f5e9;
    --error-fondo: #fdecea;
    /* Escala secuencial azul para matrices */
    --calor-1: #cde2fb; --calor-2: #9ec5f4; --calor-3: #6da7ec; --calor-4: #2a78d6; --calor-5: #184f95;
}

* { box-sizing: border-box; }
body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    margin: 0; background: var(--fondo); color: var(--texto); line-height: 1.45;
}

/* --- Cabecera y menú --- */
header { background: var(--cabecera); color: #fff; padding: 12px 20px; }
header h1 { margin: 0; font-size: 1.4rem; flex: 1; }
.marca { display: flex; align-items: center; gap: 14px; }
.marca-murcielago { height: 46px; width: auto; filter: invert(1); } /* dibujo negro → blanco sobre la cabecera oscura */
.marca-alnus { display: block; flex-shrink: 0; border-radius: 4px; }
.marca-alnus img { display: block; height: 52px; width: auto; }
.marca-alnus:hover, .marca-alnus:focus-visible { outline: 2px solid rgba(255,255,255,.5); outline-offset: 3px; }
@media (max-width: 560px) {
    .marca { gap: 8px; }
    .marca-murcielago { height: 30px; }
    header h1 { font-size: 1.1rem; }
    .marca-alnus img { height: 38px; }
}
nav { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 4px 16px; }
nav a { color: #b8c4cf; text-decoration: none; font-weight: 600; padding: 2px 0; border-bottom: 2px solid transparent; }
nav a:hover { color: #fff; }
nav a.active { color: #fff; border-bottom-color: #fff; }
nav form.salir { margin-left: auto; }
nav form.salir button {
    background: none; border: 0; padding: 2px 0; margin: 0; cursor: pointer;
    color: #b8c4cf; font: inherit; border-bottom: 2px solid transparent;
}
nav form.salir button:hover { color: #fff; }

main {
    max-width: 960px; margin: 20px auto; padding: 20px;
    background: var(--superficie); border-radius: 8px; box-shadow: 0 2px 5px rgba(0,0,0,.08);
}
main.ancha { max-width: 1400px; }
h2 { margin-top: 0; }
h3 { margin-top: 2em; }
section { scroll-margin-top: 10px; }

/* --- Formularios --- */
.formulario { display: grid; gap: 14px; max-width: 420px; margin-bottom: 36px; }
.fila-campos { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
label { display: flex; flex-direction: column; font-weight: 600; gap: 4px; }
label small, .nota { font-weight: normal; color: var(--texto-suave); font-size: .9em; }
label.en-linea { flex-direction: row; align-items: center; gap: 6px; }
form.en-linea { display: inline; }
input, select, textarea { font: inherit; padding: 7px 8px; border: 1px solid #c4c9ce; border-radius: 4px; background: #fff; }
input[type=checkbox] { width: 1.15em; height: 1.15em; padding: 0; }

button {
    font: inherit; font-weight: 600; background: var(--primario); color: #fff;
    padding: 9px 14px; border: none; border-radius: 4px; cursor: pointer;
}
button:hover { background: var(--primario-hover); }
button:disabled { opacity: .45; cursor: not-allowed; }
.btn-secundario { background: var(--secundario); }
.btn-secundario:hover { background: #0277bd; }
.btn-accion { padding: 4px 9px; font-size: .9em; }
.btn-editar { background: var(--aviso); color: #000; }
.btn-editar:hover { background: #f5b800; }
.btn-borrar { background: var(--peligro); }
.btn-borrar:hover { background: #c62828; }
.btn-cancelar { background: #bdbdbd; color: #000; }
.btn-cancelar:hover { background: #a5a5a5; }
.btn-guardar { background: var(--primario); }
.btn-mini { padding: 2px 8px; font-size: .85em; background: #e7ecf0; color: var(--texto); font-weight: normal; }
.btn-mini:hover { background: #d5dde3; }
td.acciones { white-space: nowrap; }
td.acciones > * + * { margin-left: 4px; }
/* Panel de edición dentro de una tabla ancha: se queda pegado a la izquierda y no pasa del ancho de la pantalla */
.panel-edicion { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px 14px;
                 position: sticky; left: 0; max-width: calc(100vw - 60px); }
.panel-edicion > strong { align-self: center; }
.panel-edicion .nota { flex-basis: 100%; order: 1; }
.panel-edicion .botones { display: flex; gap: 4px; margin-left: auto; }

/* --- Avisos --- */
.aviso { padding: 10px 14px; border-radius: 4px; font-weight: 600; }
.aviso.exito { background: var(--exito-fondo); color: #1b5e20; }
.aviso.error { background: var(--error-fondo); color: #b71c1c; }

/* --- Tablas --- */
.tabla-scroll { overflow-x: auto; margin-top: 12px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; border: 1px solid var(--borde); text-align: left; vertical-align: top; }
thead th { background: #f2f4f6; position: sticky; top: 0; z-index: 1; }
.fila-edicion { background: #fffbea; }
tr.de-baja > td { color: var(--texto-suave); background: #f7f7f5; }
.etiqueta-baja { display: inline-block; padding: 1px 7px; border-radius: 999px; background: #e9e4dc; color: #6b5a3e; font-size: .85em; font-weight: 600; }
small.periodo { display: block; color: var(--texto-suave); }
.centro { text-align: center; }

/* --- Barras de controles y chips --- */
.barra { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px; margin-bottom: 12px; }
.barra form { display: flex; align-items: center; gap: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 3px 10px; border-radius: 999px; border: 1px solid var(--borde); text-decoration: none; color: var(--texto); font-size: .9em; }
.chip:hover { background: #eef2f5; }
.chip.activo { background: var(--cabecera); color: #fff; border-color: var(--cabecera); }
.filtros { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px 20px; margin-bottom: 14px; background: #edf2f7; padding: 10px 12px; border-radius: 6px; }
.indice { margin-bottom: 8px; }

/* --- Hoja de censo --- */
.resumen { background: #edf2f7; padding: 8px 12px; border-radius: 6px; }
.kpi-mini b { font-size: 1.15em; }
.hoja td { padding: 6px 8px; }
.hoja tr.fila-caja:not(.revisada) { background: #fafafa; color: var(--texto-suave); }
.hoja tr.modificada td:first-child { box-shadow: inset 4px 0 0 var(--aviso); }
.hoja tr.con-error { outline: 3px solid var(--peligro); }
.col-caja strong { display: block; }
.col-caja small { color: var(--texto-suave); }
.col-obs { min-width: 290px; }
.obs { display: flex; gap: 4px; margin-bottom: 4px; }
.obs select { flex: 1; min-width: 0; max-width: 230px; }
.obs .o-n { width: 64px; }
.obs .quitar { padding: 0 8px; background: transparent; color: var(--texto-suave); font-size: 1.1em; }
.obs .quitar:hover { color: var(--peligro); background: transparent; }
.col-etq { min-width: 220px; }
.etq { display: inline-flex; flex-direction: row; align-items: center; gap: 3px; font-weight: normal; font-size: .85em;
       margin: 0 8px 3px 0; white-space: nowrap; }
.etq input { width: .95em; height: .95em; }
.f-coment { width: 100%; min-width: 160px; resize: vertical; }
.fecha-censo { font-size: 1.05em; }
.barra-guardar {
    position: sticky; bottom: 0; display: flex; justify-content: flex-end; align-items: center; gap: 16px;
    background: var(--superficie); padding: 12px 0; border-top: 1px solid var(--borde); margin-top: 8px;
}
#pendientes { color: #8a6d00; font-weight: 600; }

/* --- Inicio --- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 28px; }
.kpi { background: #edf2f7; border-radius: 8px; padding: 14px; display: flex; flex-direction: column; }
.kpi-valor { font-size: 1.9rem; font-weight: 700; color: var(--cabecera); }
.kpi-texto { color: var(--texto-suave); font-size: .92em; }
.tarjetas { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.tarjeta { display: flex; flex-direction: column; gap: 4px; padding: 14px; border: 1px solid var(--borde); border-radius: 8px;
           text-decoration: none; color: var(--texto); }
.tarjeta:hover { border-color: var(--secundario); background: #f7fbfe; }
.tarjeta span { color: var(--texto-suave); font-size: .92em; }
.ajustes { margin-top: 32px; }
.ajustes summary { cursor: pointer; font-weight: 600; margin-bottom: 12px; }

/* --- Resultados --- */
.acceso-socios { margin-top: 32px; text-align: right; }
#map { height: 480px; border-radius: 6px; }
.grafica { position: relative; height: 320px; }
.grafica.baja { height: 160px; }
.leyenda-mapa { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; font-size: .9em; color: var(--texto-suave); }
.punto { display: inline-block; width: 14px; height: 14px; border-radius: 50%; vertical-align: middle; margin-right: -8px; }
.punto.ocupada { background: #2a78d6; }
.punto.vacia { background: #fff; border: 2px solid #52514e; }
.punto.norev { border: 1.5px dashed #8a8984; }
.matriz th, .matriz td { padding: 4px 6px; text-align: center; font-size: .85em; white-space: nowrap; }
.matriz tbody th { text-align: left; position: sticky; left: 0; background: #f2f4f6; }
.matriz td small { display: block; font-size: .8em; opacity: .8; }
.matriz tbody th small { font-weight: normal; color: var(--texto-suave); }
.celda { display: inline-block; min-width: 2.4em; padding: 1px 6px; text-align: center; border: 1px solid var(--borde); }
.calor-nr { background: #f4f4f2; color: #b0b0aa; }
.calor-fuera { background: repeating-linear-gradient(135deg, #ecebe7 0 3px, #f7f7f5 3px 7px); color: #b0b0aa; }
.calor-0 { background: #fff; color: var(--texto-suave); }
.calor-1 { background: var(--calor-1); }
.calor-2 { background: var(--calor-2); }
.calor-3 { background: var(--calor-3); color: #fff; }
.calor-4 { background: var(--calor-4); color: #fff; }
.calor-5 { background: var(--calor-5); color: #fff; }

@media (max-width: 600px) {
    main { margin: 0; border-radius: 0; padding: 14px; }
    header h1 { font-size: 1.15rem; }
    .fila-campos { grid-template-columns: 1fr; }
    #map { height: 360px; }
}

/* Grupos de cajas en el mapa */
.resumen-mapa { background: #edf2f7; padding: 8px 12px; border-radius: 6px; margin: 0 0 10px; }
.grupo-mapa { background: transparent; }
.grupo-mapa div {
    width: 100%; height: 100%; border-radius: 50%; display: flex; flex-direction: column; align-items: center; justify-content: center;
    background: #fff; border: 2px solid #52514e; color: #2b2b2b; line-height: 1.05; box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
.grupo-mapa.con-individuos div { background: rgba(42, 120, 214, .88); border-color: #fff; color: #fff; }
.grupo-mapa small { font-size: 9px; white-space: nowrap; }
.punto.grupo { width: 18px; height: 18px; background: rgba(42, 120, 214, .88); border: 2px solid #fff; box-shadow: 0 0 0 1px #52514e; }
