:root {
  --azul: #2b4c9c;
  --azul-claro: #cad2e6;
  --gris: #e4e4e3;
  --foco: #2b4c9c;
  --fondo: #f5f6f9;
  --borde: #e4e4e3;
  --texto: rgb(20, 40, 65);
  --suave: rgb(95, 108, 124);
  --error: rgb(160, 30, 30);
  --nuevo: rgb(0, 110, 70);
}

* { box-sizing: border-box; }

html { font: 16px/1.5 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; color: var(--texto); background: var(--fondo); }
body { margin: 0; min-height: 100vh; display: flex; flex-direction: column; }
main { flex: 1; width: 100%; max-width: 1180px; margin: 0 auto; padding: 24px 16px 40px; }
h1 { font-size: 1.5rem; margin: 0 0 16px; color: var(--azul); }
a { color: var(--azul); }

.cabecera { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 24px; padding: 10px 24px; background: white; color: var(--texto); border-bottom: 3px solid var(--azul); position: relative; z-index: 2; }
.cabecera a { color: var(--azul); }
.marca { display: inline-block; line-height: 0; }
.marca img { height: 49px; width: auto; display: block; }
.usuario { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 16px; font-size: .92rem; }
.en-linea { display: inline; margin: 0; }
button.enlace { background: none; border: 0; padding: 0; color: var(--azul); font: inherit; text-decoration: underline; cursor: pointer; }

.pie { position: relative; z-index: 1; padding: 14px 24px; font-size: .82rem; color: var(--suave); background: white; border-top: 1px solid var(--borde); text-align: center; }

.tarjeta { background: white; border: 1px solid var(--borde); border-radius: 8px; padding: 24px; }
.estrecha { max-width: 440px; margin: 32px auto; }

label { display: block; margin: 14px 0 4px; font-weight: 600; font-size: .92rem; }
input[type=text], input[type=tel], input[type=email], input[type=password], input[type=search], input[type=date] {
  width: 100%; height: 40px; padding: 0 10px; font: inherit; color: var(--texto); background: white; border: 1px solid var(--azul); border-radius: 6px;
}
input:focus-visible, button:focus-visible, a:focus-visible { outline: 3px solid var(--foco); outline-offset: 1px; }
.suave { color: var(--suave); font-weight: 400; }

button, .boton { display: inline-block; height: 38px; padding: 0 14px; font: inherit; line-height: 36px; color: var(--azul); background: white; border: 1px solid var(--azul); border-radius: 6px; text-decoration: none; cursor: pointer; white-space: nowrap; }
button:hover, .boton:hover { background: #eef1f8; }
button.primario { color: white; background: var(--azul); margin-top: 18px; }
button.primario:hover { background: #223e82; }

.aviso { padding: 10px 14px; border-radius: 6px; background: #eef1f8; border: 1px solid var(--azul-claro); }
.aviso.error { background: rgb(253, 236, 236); border-color: var(--error); color: var(--error); }
.aviso.nuevo { background: rgb(230, 247, 238); border-color: var(--nuevo); color: var(--nuevo); }

.filtros { display: grid; grid-template-columns: 2fr 1fr 1fr auto auto; gap: 0 14px; align-items: end; background: white; border: 1px solid var(--borde); border-radius: 8px; padding: 6px 16px 16px; margin-bottom: 12px; }
.filtros .check { display: flex; align-items: center; gap: 6px; padding-bottom: 8px; }
.filtros .check label { margin: 0; font-weight: 400; }
.filtros .botones { display: flex; gap: 8px; align-items: center; }
.filtros button.primario { margin-top: 0; }
.total { color: var(--suave); margin: 8px 0; }

.tabla-caja { overflow-x: auto; background: white; border: 1px solid var(--borde); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--borde); }
thead th { background: rgba(43, 76, 156, .85); color: white; font-weight: 600; white-space: nowrap; text-align: left; letter-spacing: .09em; }
tbody tr { background: white; }
tbody tr:hover { background: #eef1f8; }
td.accion form { margin: 0; }
.etiqueta { display: inline-block; padding: 1px 10px; border-radius: 999px; font-size: .8rem; font-weight: 700; }
.etiqueta.nuevo { background: rgb(230, 247, 238); color: var(--nuevo); border: 1px solid var(--nuevo); }
.vacio { padding: 32px 12px; text-align: center; color: var(--suave); }
.oculto { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.paginas { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 16px; }

@media (max-width: 860px) {
  .filtros { grid-template-columns: 1fr 1fr; }
  .filtros > div:first-child { grid-column: 1 / -1; }
  thead { display: none; }
  table, tbody, tr, td { display: block; width: 100%; }
  tr { padding: 10px 12px; border-bottom: 1px solid var(--borde); }
  td { border: 0; padding: 3px 0; }
  td::before { content: attr(data-etq) ": "; font-weight: 600; color: var(--suave); }
  td.accion::before { content: ""; }
  td.muestras { max-width: none; }
}

/* --- Patológicos, resumen y descarga múltiple --- */
.resumen { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-bottom: 12px; }
.boton.verde { display: inline-flex; align-items: center; gap: 16px; height: 40px; padding: 0 16px 0 18px; color: var(--nuevo); border-color: var(--nuevo); background: rgb(230, 247, 238); font-weight: 600; }
.boton.verde:hover, .boton.verde.activo { background: var(--nuevo); color: white; }
.boton.verde .contador { min-width: 26px; padding: 0 9px; margin-left: 2px; border-radius: 999px; background: var(--nuevo); color: white; text-align: center; line-height: 22px; }
.boton.verde:hover .contador, .boton.verde.activo .contador { background: white; color: var(--nuevo); }
.boton.alerta { display: inline-flex; align-items: center; gap: 16px; height: 40px; padding: 0 16px 0 18px; color: #8e1b1b; border-color: #c62828; background: rgb(253, 236, 236); font-weight: 600; }
.boton.alerta:hover, .boton.alerta.activo { background: #c62828; color: white; }
.boton.alerta .contador { min-width: 26px; padding: 0 9px; margin-left: 2px; border-radius: 999px; background: #c62828; color: white; text-align: center; line-height: 22px; }
.boton.alerta:hover .contador, .boton.alerta.activo .contador { background: white; color: #c62828; }
.icono-alerta { vertical-align: middle; flex: none; }
tr.patologico td:first-child { box-shadow: inset 4px 0 0 #c62828; }
tr.patologico { background: rgb(255, 245, 245) !important; }
td.alerta-celda, th.alerta-celda { width: 34px; padding-left: 4px; padding-right: 4px; text-align: center; }
td.sel, th.sel { width: 36px; padding-left: 14px; padding-right: 4px; }
td.sel input, th.sel input { width: 18px; height: 18px; cursor: pointer; }
.filtros .checks { display: flex; flex-direction: column; }
.barra-lote { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin: 22px 0 16px; }
.barra-lote button.primario { margin-top: 0; background: #5b78bd; border-color: #5b78bd; }
.barra-lote button.primario:hover:not(:disabled) { background: #4a66aa; }
.barra-lote button:disabled { opacity: .5; cursor: not-allowed; }

/* --- Registro, recuperación y verificación --- */
.tarjeta.ancha { max-width: 820px; margin: 24px auto; }
.rejilla { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
.campo { display: flex; flex-direction: column; }
.campo input { width: 100%; box-sizing: border-box; }
.campo .ayuda { color: var(--suave); font-size: .82rem; margin-top: 3px; }
.campo.con-error input { border-color: var(--error); }
.error-campo { color: var(--error); font-size: .85rem; margin-top: 3px; }
.check-legal { flex-direction: row; flex-wrap: wrap; align-items: flex-start; gap: 4px 10px; margin-top: 18px; }
.check-legal input { width: 20px; height: 20px; margin-top: 3px; flex: none; }
.check-legal label { margin: 0; font-weight: 400; flex: 1; min-width: 220px; }
.check-legal .error-campo { width: 100%; }
.botones-form { display: flex; gap: 10px; align-items: center; margin-top: 10px; }
.botones-form button.primario { margin-top: 0; }
.trampa { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
.enlaces-login { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 16px; margin: 18px 0 0; font-size: .92rem; }
.texto-legal h2 { font-size: 1.05rem; color: var(--azul); margin: 22px 0 6px; }
.texto-legal p, .texto-legal li { line-height: 1.55; }
.ultimo-acceso { margin: -6px 0 14px; font-size: .86rem; }
.recordar { display: flex; align-items: center; gap: 8px; margin: 14px 0 4px; }
.recordar label { margin: 0; font-weight: 400; }
.recordar input { width: auto; height: auto; margin: 0; accent-color: var(--azul); }
.pequeno { font-size: .82rem; margin: 2px 0 8px; }
.correos { border: 0; margin: 8px 0 0; padding: 0; }
.opcion-correo { display: flex; align-items: center; gap: 10px; margin: 8px 0; padding: 10px 12px; font-weight: 400; border: 1px solid var(--borde); border-radius: 6px; cursor: pointer; }
.opcion-correo:hover { border-color: var(--azul); }
.opcion-correo input { width: auto; height: auto; margin: 0; accent-color: var(--azul); }
.solo-lectores { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.reenviar { display: flex; gap: 16px; align-items: center; margin-top: 14px; }
button.enlace-azul { background: none; border: 0; padding: 0; height: auto; line-height: inherit; color: var(--azul); text-decoration: underline; cursor: pointer; font: inherit; }
button.enlace-azul:hover { background: none; }
@media (max-width: 640px) { .rejilla { grid-template-columns: 1fr; } }

/* --- Entrada con imagen --- */
main:has(.entrada) { max-width: none; padding: 0; }
.entrada { position: relative; margin: 0; padding: 48px 16px; min-height: calc(100vh - 150px); display: flex; align-items: center; justify-content: center; background: linear-gradient(rgba(255, 255, 255, .25), rgba(255, 255, 255, .25)), #fff url(/static/fondo-login.jpg) center bottom / cover no-repeat; }
.entrada .tarjeta { position: relative; width: 100%; max-width: 440px; margin: 0; background: rgba(43, 76, 156, .85); border-color: transparent; box-shadow: 0 12px 40px rgba(43, 76, 156, .10); color: white; }
.entrada h1, .entrada label { color: white; letter-spacing: .09em; }
.entrada a { color: white; }
.entrada input[type=text], .entrada input[type=password] { border-color: #8c98b8; }
.entrada input:focus-visible, .entrada button:focus-visible, .entrada a:focus-visible { outline-color: white; }
.entrada button.primario { color: var(--azul); background: var(--azul-claro); border-color: var(--azul-claro); }
.entrada button.primario:hover { background: white; }
@media (max-width: 640px) { .marca img { height: 34px; } }
.boton.todos { display: inline-flex; align-items: center; height: 40px; padding: 0 18px; font-weight: 600; }
.boton.todos.activo { background: var(--azul); border-color: var(--azul); color: white; }
.pie p { margin: 2px 0; }
.pie a { color: var(--azul); }

/* Historial del paciente (icono "i" y ventana) */
/* Icono de información (a la izquierda del nombre del paciente) */
.info-paciente { display: inline-flex; line-height: 0; border-radius: 50%; vertical-align: middle; }

.info-paciente:hover svg, .info-paciente:focus-visible svg { filter: brightness(.85); }
.info-paciente:focus-visible { outline: 2px solid var(--azul); outline-offset: 2px; }
.ventana-paciente { width: min(760px, 94vw); max-height: 88vh; padding: 20px 22px; border: 1px solid var(--azul); border-radius: 10px; overflow: auto; }
.ventana-paciente::backdrop { background: rgba(0, 0, 0, .45); }
.cerrar-ventana { position: absolute; top: 8px; right: 10px; width: 34px; height: 34px; padding: 0; font-size: 1.4rem; line-height: 30px; }
.historial h2 { margin: 0 0 4px; color: var(--azul); }
.historial .anio h3 { margin: 18px 0 6px; padding-bottom: 4px; border-bottom: 2px solid var(--azul-claro); color: var(--azul); }
.tabla-hist td { padding: 8px 10px; }
.tabla-hist td::before { content: none !important; }

.todos-paciente { display: flex; align-items: center; gap: 12px; margin: 12px 0 4px; }
.todos-paciente form { margin: 0; }
.check-todos { display: inline-flex; align-items: center; gap: 6px; }
.tabla-hist td.sel { width: 34px; padding-right: 0; }
td.info-celda, th.info-celda { width: 34px; padding-left: 4px; padding-right: 0; text-align: center; }
@media (max-width: 860px) {
  td.info-celda::before { content: ""; }
  td.info-celda:empty { display: none; }
}

/* --- Fondos de página --- */
body.fondo-blanco { background: white; }
body.fondo-skyline { position: relative; isolation: isolate; background: white; }
body.fondo-skyline::before { content: ""; position: absolute; left: 0; right: 0; bottom: 0; width: 100%; aspect-ratio: 1961 / 687; background: url(/static/skyline.png) center bottom / 100% 100% no-repeat; opacity: .75; pointer-events: none; z-index: -1; }
body.fondo-skyline main { position: relative; }

/* --- Listado: filtros y tabla con transparencia y sombra --- */
body.fondo-skyline .filtros { background: rgba(255, 255, 255, .94); border-color: #c3cde6; }
.tabla-caja { background: rgba(255, 255, 255, .96); border-color: #c3cde6; }
body.fondo-skyline .tabla-caja { box-shadow: 0 12px 36px rgba(43, 76, 156, .35); }
.historial .tabla-caja { border-color: #dfe3ee; box-shadow: none; }

/* --- Filas nuevas en negrita; "Descargado" en cursiva --- */
tr[data-nuevo] td:not(.sel):not(.alerta-celda):not(.info-celda):not(.accion) { font-weight: 700; }
.descargado { font-style: italic; color: #4a5568; }

/* --- Botones de descarga con icono --- */
.ico { flex: none; }
button.primario:has(.ico) { display: inline-flex; align-items: center; gap: 8px; }
td.accion button.boton { display: inline-flex; align-items: center; justify-content: center; gap: 8px; width: 160px; padding: 0 14px; line-height: 1; color: var(--azul); background: var(--azul-claro); border-color: var(--azul); }
td.accion button.boton:hover { background: #b8c3e0; }
td.accion button.boton.de-nuevo { gap: 6px; padding: 0 10px; font-size: 13px; }

/* --- Historial: pastillas de año y ventana --- */
.historial .anio h3 .pastilla { display: inline-block; padding: 2px 16px; border-radius: 999px; background: rgba(43, 76, 156, .75); color: white; letter-spacing: .09em; }
.ventana-paciente { background: white; box-shadow: 0 20px 60px rgba(43, 76, 156, .35); }
.ventana-paciente::backdrop { background: rgba(255, 255, 255, .7); }

/* Historial: las columnas de los distintos años quedan alineadas */
.tabla-hist { table-layout: fixed; }
.tabla-hist td.sel, .tabla-hist td.alerta-celda { width: 38px; }
.tabla-hist td.accion { width: 190px; }
