@font-face { font-family: Roboto; font-weight: 400; font-display: swap; src: url(fonts/roboto-400.woff2) format("woff2"); }
@font-face { font-family: Roboto; font-weight: 500; font-display: swap; src: url(fonts/roboto-500.woff2) format("woff2"); }
@font-face { font-family: Roboto; font-weight: 700; font-display: swap; src: url(fonts/roboto-700.woff2) format("woff2"); }

:root {
    color-scheme: light dark;
    --azul: #0072b9;
    --marca: #0072b9;
    --azul-osc: #005a93;
    --naranja: #6ee7b7;
    --rojo: #e3001b;
    --rojo-t: #e3001b;
    --verde: #1e7e34;
    --bg: #f4f6fa;
    --card: #fff;
    --texto: #1e2a44;
    --suave: #5a6580;
    --borde: #e3e7f0;
    --hover: #eef2fb;
    --link: #0072b9;
    --g-venc: #e3001b;
    --g-warn: #c77700;
    --g-azul: #0072b9;
    --g-gris: #6b7690;
    --g-ok: #1e7e34;
    --tinte: 5%;
    --sidebar-w: 15rem;
}

@media (prefers-color-scheme: dark) {
    :root {
        --marca: #0b4a75;
        --bg: #0f1424;
        --card: #182038;
        --texto: #e8eaf2;
        --suave: #9aa4c0;
        --borde: #28324f;
        --hover: #1f2945;
        --link: #5db4ee;
        --azul-osc: #004a78;
        --rojo-t: #ff6b7d;
        --g-venc: #ff6b7d;
        --g-warn: #f5b942;
        --g-azul: #4aa3e0;
        --g-gris: #9aa4c0;
        --g-ok: #4cc470;
        --tinte: 8%;
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: Roboto, system-ui, sans-serif;
    font-size: 15px;
    background: var(--bg);
    color: var(--texto);
}

a { color: var(--link); }
h1 { font-size: 1.5rem; font-weight: 500; margin: 0 0 1.25rem; }
h2 { font-size: 1.05rem; font-weight: 500; margin: 0 0 .75rem; }

/* ---------- Layout ---------- */
.nav-toggle { position: absolute; opacity: 0; pointer-events: none; }

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-w);
    background: var(--marca);
    color: #fff;
    display: flex;
    flex-direction: column;
    z-index: 30;
    transition: transform .2s;
}

.sidebar .logo { color: #fff; text-decoration: none; display: block; padding: 1.25rem 1.5rem; border-bottom: 1px solid rgb(255 255 255 / .18); }
.sidebar .logo img { display: block; width: 8.5rem; height: auto; }
.sidebar .sub { font-size: .8rem; margin-top: .35rem; }

.sidebar nav { padding: .75rem 0; flex: 1; }

.sidebar nav a {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .7rem 1.5rem;
    color: #fff;
    text-decoration: none;
    border-left: 3px solid transparent;
}
.sidebar nav a:hover { background: rgb(255 255 255 / .1); }
.sidebar nav a.active { background: rgb(255 255 255 / .16); border-left-color: var(--naranja); font-weight: 500; }

.icono { width: 1.25rem; height: 1.25rem; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.contenido { margin-left: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: .7rem 1.5rem;
    background: var(--card);
    border-bottom: 1px solid var(--borde);
}
.topbar .espacio { flex: 1; }
.topbar .usuario { display: flex; align-items: center; gap: .65rem; min-width: 0; }
.topbar .avatar { width: 2rem; height: 2rem; border-radius: 50%; background: var(--azul); color: #fff; display: grid; place-items: center; font-weight: 500; font-size: .85rem; flex: none; }
.topbar .avatar .icono { width: 1.1rem; height: 1.1rem; }
.topbar .nombre { color: var(--texto); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 12rem; }
.topbar .hamburguesa { display: none; cursor: pointer; padding: .25rem; }
.nav-toggle:focus-visible ~ .contenido .hamburguesa { outline: 2px solid var(--link); }

.pie { display: flex; gap: 1rem; flex-wrap: wrap; padding: .9rem 1.5rem; border-top: 1px solid var(--borde); color: var(--suave); font-size: .8rem; }
.pie .espacio { flex: 1; }

.backdrop { display: none; }

main { padding: 1.5rem; width: 100%; max-width: 90rem; margin: 0 auto; flex: 1; }

/* Sin sesión (login): sin sidebar. */
.solo { min-height: 100vh; display: grid; place-items: center; padding: 1rem; background: var(--marca); }
.solo main { padding: 0; max-width: 24rem; }

@media (max-width: 900px) {
    .sidebar { transform: translateX(-100%); }
    .contenido { margin-left: 0; }
    .topbar .hamburguesa { display: block; }
    .nav-toggle:checked ~ .sidebar { transform: none; box-shadow: 0 0 2rem rgb(0 0 0 / .4); }
    .nav-toggle:checked ~ .backdrop { display: block; position: fixed; inset: 0; background: rgb(0 0 0 / .4); z-index: 20; }
    main { padding: 1rem; }
}

/* ---------- Componentes ---------- */
.card {
    background: var(--card);
    border: 1px solid var(--borde);
    border-radius: .5rem;
    padding: 1rem 1.25rem;
    box-shadow: 0 1px 2px rgb(0 0 0 / .05);
}
.card + .card { margin-top: 1rem; }
.kpis .card + .card, .graficos .card + .card { margin-top: 0; }
h1:focus { outline: none; }

/* ponytail: el span 3 supone exactamente 3 tarjetas a la derecha; con otro KPI nuevo se rehace la grilla. */
.kpis { display: grid; grid-template-columns: 1.2fr 1fr; gap: 1rem; margin-bottom: 1rem; }
.kpis:has(.cero) { grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); }

.kpi { --c: var(--g-azul); display: flex; align-items: center; gap: 1rem; color: var(--texto); border-left: 4px solid var(--c); text-decoration: none; padding: .75rem 1rem; min-width: 0; }
.kpi .icono { width: 1.75rem; height: 1.75rem; color: var(--c); }
.kpi .valor { font-size: 1.5rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi .titulo { font-size: .9rem; color: var(--suave); }
.kpi .nota { font-size: .75rem; color: var(--suave); margin-top: .2rem; }
.kpi.verde { --c: var(--g-ok); }
.kpi.naranja { --c: var(--g-warn); }
.kpi.rojo { --c: var(--g-venc); grid-column: 1; grid-row: 1 / span 3; flex-direction: column; align-items: flex-start; justify-content: center; gap: .5rem; padding: 1.5rem;
    background: color-mix(in srgb, var(--c) var(--tinte), var(--card)); }
.kpi.rojo .icono { width: 2.5rem; height: 2.5rem; }
.kpi.rojo .valor { font-size: 3.2rem; line-height: 1; color: var(--c); }
.kpi.rojo .titulo { color: var(--texto); font-size: 1rem; margin-top: .25rem; }
.kpi.rojo .nota { display: block; margin-top: .75rem; font-size: .9rem; color: var(--texto); font-weight: 500; text-decoration: underline; text-underline-offset: .2em; }
/* 0 vencidas: sin alarma, tarjeta normal en verde. */
.kpi.rojo.cero { --c: var(--g-ok); grid-column: auto; grid-row: auto; flex-direction: row; align-items: center; gap: 1rem; padding: .75rem 1rem; background: var(--card); }
.kpi.rojo.cero .icono { width: 1.75rem; height: 1.75rem; }
.kpi.rojo.cero .valor { font-size: 1.5rem; color: var(--texto); }
.kpi.rojo.cero .titulo { font-size: .9rem; color: var(--suave); margin: 0; }

.kpis > .esq-kpi:first-child { grid-column: 1; grid-row: 1 / span 3; }

@media (max-width: 700px) {
    .kpis { grid-template-columns: 1fr; }
    .kpi.rojo, .kpis > .esq-kpi:first-child { grid-column: auto; grid-row: auto; }
}

.graficos { display: grid; grid-template-columns: repeat(auto-fit, minmax(20rem, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.grafico { position: relative; height: 16rem; }

.aviso { font-size: .8rem; color: var(--suave); margin: 0 0 1rem; }

.badge { display: inline-block; padding: .1rem .55rem; border-radius: 1rem; font-size: .78rem; font-weight: 500; color: #fff; white-space: nowrap; }
.badge.danger { background: var(--rojo); }
.badge.warn { background: #f5b942; color: #3b2700; }
.badge.ok { background: var(--verde); }

.error { color: var(--rojo-t); font-weight: 500; }
.cargando { opacity: .7; }
.vacio { color: var(--suave); }

.vacio-d { display: grid; justify-items: center; gap: .35rem; text-align: center; padding: 2rem 1rem; }
.vacio-d .icono { width: 2rem; height: 2rem; color: var(--suave); }
.vacio-d p { margin: 0; }
.vacio-d .t { margin-top: .25rem; font-weight: 500; }
.vacio-d p:not(.t) { color: var(--suave); }
.vacio-d button { margin-top: .75rem; }

.aviso-err { display: flex; align-items: center; gap: 1rem; border-left: 4px solid var(--rojo-t); }
.aviso-err .icono { width: 1.75rem; height: 1.75rem; color: var(--rojo-t); }
.aviso-err > div { flex: 1; }
.aviso-err p { margin: 0; }
.aviso-err .t { font-weight: 500; }
.aviso-err p:not(.t) { color: var(--suave); }

/* ---------- Formularios ---------- */
input {
    font: inherit;
    padding: .45rem .65rem;
    border: 1px solid var(--borde);
    border-radius: .3rem;
    background: var(--card);
    color: inherit;
}
input:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid var(--link); outline-offset: 1px; }
.sidebar a:focus-visible { outline-color: #fff; }

button {
    font: inherit;
    padding: .45rem .9rem;
    border: 1px solid var(--azul);
    border-radius: .3rem;
    background: var(--azul);
    color: #fff;
    cursor: pointer;
}
button:hover:not(:disabled) { background: var(--azul-osc); }
button:disabled { opacity: .6; cursor: default; }
button.sec { background: transparent; color: var(--link); }
button.sec:hover:not(:disabled) { background: var(--hover); }

button.link { background: none; border: 0; padding: 0; color: var(--link); display: flex; align-items: center; gap: .35rem; }
button.link:hover { background: none; text-decoration: underline; }

.filtros { display: flex; align-items: end; gap: .5rem; margin-bottom: 1rem; flex-wrap: wrap; }
.campo { display: grid; gap: .25rem; }
.campo.grow { flex: 1; min-width: 12rem; max-width: 22rem; }
.campo.grow input { width: 100%; }

.login { display: grid; gap: .4rem; }
.login h1 { margin-bottom: .5rem; }
.login label { font-size: .85rem; color: var(--suave); margin-top: .5rem; }
.login button { margin-top: 1rem; }
.login .logo-login { background: var(--marca); margin: -1rem -1.25rem 1rem; padding: 1.25rem; border-radius: .5rem .5rem 0 0; }
.login .logo-login img { display: block; width: 9rem; margin: 0 auto; }
.aviso-login { margin: 0 0 .5rem; padding: .6rem .75rem; border-left: 4px solid var(--rojo-t); border-radius: .3rem; background: color-mix(in srgb, var(--rojo-t) var(--tinte), var(--card)); font-size: .9rem; }
.pw { position: relative; display: grid; }
.pw input { padding-right: 5rem; }
.pw .ver { position: absolute; inset: 0 0 0 auto; margin: 0; background: none; border: 0; border-radius: 0 .3rem .3rem 0; color: var(--link); padding: 0 .75rem; font-size: .85rem; }
.pw .ver:hover:not(:disabled) { background: none; text-decoration: underline; }
.pw .ver:focus-visible { outline-offset: -2px; }
input::-ms-reveal { display: none; }

/* ---------- Tablas ---------- */
.tabla-wrap { overflow-x: auto; }

table { border-collapse: collapse; width: 100%; }

th, td { padding: .6rem .75rem; text-align: left; white-space: nowrap; border-bottom: 1px solid var(--borde); }

th { font-size: .85rem; font-weight: 500; color: var(--suave); }
tbody tr:last-child > td { border-bottom: 0; }
tbody tr:not(.items):hover > td { background: var(--hover); }

td.id { font-weight: 500; }
td.aux { color: var(--suave); }

/* El estado se ve en el borde de la fila, sin scrollear hasta la columna Estado. */
tr.warn > td:first-child { box-shadow: inset 3px 0 0 var(--g-warn); }
tr.danger > td:first-child { box-shadow: inset 3px 0 0 var(--g-venc); }
tr.danger > td { background: color-mix(in srgb, var(--g-venc) var(--tinte), var(--card)); }

/* Fila abierta: se une visualmente a su detalle. */
tr.abierta > td, tr.items > td { background: var(--hover); }
tr.abierta > td:first-child, tr.items > td { box-shadow: inset 3px 0 0 var(--link); }
tr.items > td { padding: .25rem 1.5rem .9rem 3.2rem; }
tr.items table { width: auto; }
tr.items th { font-size: .8rem; }
tr.items tbody tr:hover > td { background: none; }

td.acciones, th.acciones { width: 1%; text-align: center; }
td.num, th.num { text-align: right; }
td.num { font-variant-numeric: tabular-nums; }

button.toggle {
    background: none;
    border: 0;
    color: var(--link);
    padding: .2rem .4rem;
    line-height: 0;
    border-radius: .3rem;
}
button.toggle:hover:not(:disabled) { background: var(--hover); }

a.descargar { display: inline-flex; padding: .2rem .4rem; border-radius: .3rem; color: var(--link); }
a.descargar:hover { background: var(--hover); }

/* ---------- Paginador y fechas ---------- */
.paginador { display: flex; align-items: center; gap: .75rem; padding: .75rem 0 0; color: var(--suave); flex-wrap: wrap; }
.paginador .espacio { flex: 1; }
.filtros label { color: var(--suave); font-size: .85rem; }

/* ---------- Carga: skeletons, spinner, reconexión ---------- */
.solo-lectores { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.esq {
    background: linear-gradient(90deg, var(--borde) 25%, var(--hover) 37%, var(--borde) 63%);
    background-size: 400% 100%;
    animation: esq 1.4s ease infinite;
    border-radius: .3rem;
}
@keyframes esq { from { background-position: 100% 50%; } to { background-position: 0 50%; } }
.esq-fila { height: 1.9rem; margin: .65rem 0; }
.esq-titulo { height: 1.1rem; width: 12rem; margin-bottom: 1rem; }
.card.esq-kpi { min-height: 4.5rem; border: 0; }
.card.esq-kpi + .card { margin-top: 0; }

.recargando { opacity: .55; pointer-events: none; transition: opacity .15s; }

@keyframes giro { to { transform: rotate(360deg); } }
button.ocupado::after, .cargando::before {
    content: "";
    display: inline-block;
    width: .9em;
    height: .9em;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: giro .7s linear infinite;
    vertical-align: -.1em;
}
button.ocupado::after { margin-left: .5rem; }
.cargando::before { margin-right: .5rem; }

@media (prefers-reduced-motion: reduce) {
    .esq, button.ocupado::after, .cargando::before, .components-rejoining-animation div { animation: none; }
}

.components-reconnect-first-attempt-visible, .components-reconnect-repeated-attempt-visible,
.components-reconnect-failed-visible, .components-pause-visible,
.components-resume-failed-visible, .components-rejoining-animation { display: none; }

#components-reconnect-modal.components-reconnect-show .components-reconnect-first-attempt-visible,
#components-reconnect-modal.components-reconnect-show .components-rejoining-animation,
#components-reconnect-modal.components-reconnect-paused .components-pause-visible,
#components-reconnect-modal.components-reconnect-resume-failed .components-resume-failed-visible,
#components-reconnect-modal.components-reconnect-retrying,
#components-reconnect-modal.components-reconnect-retrying .components-reconnect-repeated-attempt-visible,
#components-reconnect-modal.components-reconnect-retrying .components-rejoining-animation,
#components-reconnect-modal.components-reconnect-failed,
#components-reconnect-modal.components-reconnect-failed .components-reconnect-failed-visible { display: block; }

#components-reconnect-modal {
    background: var(--card);
    color: var(--texto);
    width: 20rem;
    max-width: calc(100vw - 2rem);
    margin: 20vh auto;
    padding: 2rem;
    border: 0;
    border-top: 4px solid var(--naranja);
    border-radius: .5rem;
    box-shadow: 0 3px 12px rgb(0 0 0 / .35);
}
#components-reconnect-modal::backdrop { background: rgb(0 0 0 / .45); }
#components-reconnect-modal p { margin: 0; text-align: center; }

.components-reconnect-container { display: flex; flex-direction: column; align-items: center; gap: 1rem; }

.components-rejoining-animation { position: relative; width: 80px; height: 80px; }
.components-rejoining-animation div {
    position: absolute;
    border: 3px solid var(--link);
    border-radius: 50%;
    animation: components-rejoining-animation 1.5s cubic-bezier(0, .2, .8, 1) infinite;
}
.components-rejoining-animation div:nth-child(2) { animation-delay: -.5s; }

@keyframes components-rejoining-animation {
    0%, 4.9% { top: 40px; left: 40px; width: 0; height: 0; opacity: 0; }
    5% { top: 40px; left: 40px; width: 0; height: 0; opacity: 1; }
    100% { top: 0; left: 0; width: 80px; height: 80px; opacity: 0; }
}

/* Sin prerender, hasta que arranca el circuito <main> solo tiene los comentarios de Blazor: :empty ignora comentarios. */
main:empty::before {
    content: "";
    display: block;
    height: 12rem;
    border-radius: .5rem;
    background: linear-gradient(90deg, var(--borde) 25%, var(--hover) 37%, var(--borde) 63%);
    background-size: 400% 100%;
    animation: esq 1.4s ease infinite;
}
@media (prefers-reduced-motion: reduce) { main:empty::before { animation: none; } }

/* Blazor deja "show" y "retrying" activas a la vez: durante los reintentos solo va el mensaje de reintento. */
#components-reconnect-modal.components-reconnect-retrying .components-reconnect-first-attempt-visible { display: none; }
