/* NEXO - estilos base. Mobile-first. Tokens tomados del diseño (objetos L y D). */

:root {
    --bg: #F2F5F6; --sf: #FFFFFF; --sf2: #E9EFF1;
    --ink: #12232B; --ink2: #475A63; --ln: #D3DDE1;
    --pri: #0B5563; --onpri: #FFFFFF; --prs: #DCEEF1;
    --ok: #17653A; --okb: #DCF1E3;
    --wa: #7A4E00; --wab: #FFEFC7;
    --cr: #A0231A; --crb: #FBE1DE;
    --inf: #1A4E9A; --infb: #DFEAFB;
    --gr: #46525B; --grb: #E6EBEE;
    --sombra: 0 1px 2px rgba(18, 35, 43, .08), 0 4px 14px rgba(18, 35, 43, .06);
    --radio: .75rem;
    --radio-s: .5rem;
    --tactil: 2.75rem; /* 44px */
    --lateral: 16rem;
    --fuente: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --mono: 'IBM Plex Mono', ui-monospace, 'Cascadia Mono', Consolas, monospace;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #0D1A1F; --sf: #14252C; --sf2: #1B3039;
        --ink: #E9F1F3; --ink2: #A8BCC3; --ln: #2B4049;
        --pri: #63C6D8; --onpri: #04222A; --prs: #16363F;
        --ok: #86DBA6; --okb: #153424;
        --wa: #F3C877; --wab: #3A2D0F;
        --cr: #FF9F95; --crb: #44201C;
        --inf: #94BCF7; --infb: #172A47;
        --gr: #B7C3C9; --grb: #26343B;
        --sombra: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 14px rgba(0, 0, 0, .3);
        color-scheme: dark;
    }
}

:root[data-theme="dark"] {
    --bg: #0D1A1F; --sf: #14252C; --sf2: #1B3039;
    --ink: #E9F1F3; --ink2: #A8BCC3; --ln: #2B4049;
    --pri: #63C6D8; --onpri: #04222A; --prs: #16363F;
    --ok: #86DBA6; --okb: #153424;
    --wa: #F3C877; --wab: #3A2D0F;
    --cr: #FF9F95; --crb: #44201C;
    --inf: #94BCF7; --infb: #172A47;
    --gr: #B7C3C9; --grb: #26343B;
    --sombra: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 14px rgba(0, 0, 0, .3);
    color-scheme: dark;
}

/* Base */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--fuente);
    font-size: 1rem;
    line-height: 1.5;
}
h1, h2, h3, p { margin-top: 0; }
a { color: var(--pri); text-underline-offset: .15em; }
a:hover { text-decoration-thickness: 2px; }
img, svg { max-width: 100%; }
.mono { font-family: var(--mono); }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; } /* importes y números: nunca partidos */
.texto-sec { color: var(--ink2); }
.texto-centro { text-align: center; }
.solo-lectura { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.lista-simple { margin: .25rem 0 0; padding-left: 1.2rem; }
.icono { width: 1.25rem; height: 1.25rem; flex: none; }
.form-inline { display: inline; margin: 0; }

:focus-visible { outline: 3px solid var(--pri); outline-offset: 2px; border-radius: 4px; }

.skip-link {
    position: absolute; left: .5rem; top: -4rem; z-index: 100;
    background: var(--pri); color: var(--onpri);
    padding: .75rem 1rem; border-radius: var(--radio-s); font-weight: 600;
}
.skip-link:focus { top: .5rem; }

/* Botones (>=44px) */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
    min-height: var(--tactil); padding: .5rem 1rem;
    border: 1px solid transparent; border-radius: var(--radio-s);
    font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
    background: var(--sf2); color: var(--ink);
}
.btn-pri { background: var(--pri); color: var(--onpri); }
.btn-pri:hover { filter: brightness(1.08); }
.btn-sec { background: var(--sf); border-color: var(--ln); color: var(--ink); }
.btn-sec:hover { background: var(--sf2); }
.btn-bloque { display: flex; width: 100%; }
.btn-icono {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: var(--tactil); min-height: var(--tactil);
    background: transparent; border: 1px solid transparent; border-radius: var(--radio-s);
    color: var(--ink); cursor: pointer;
}
.btn-icono:hover { background: var(--sf2); }

/* Formularios */
.form { display: grid; gap: 1rem; }
.campo { display: grid; gap: .35rem; }
.campo label { font-weight: 600; }
.campo input, .campo select, .campo textarea {
    width: 100%; min-height: var(--tactil); padding: .5rem .75rem;
    background: var(--sf); color: var(--ink);
    border: 1px solid var(--ink2); border-radius: var(--radio-s);
    font: inherit;
}
.ayuda { margin: 0; font-size: .875rem; color: var(--ink2); }

/* Alertas (siempre con texto) */
.alerta { padding: .75rem 1rem; border-radius: var(--radio-s); border: 1px solid; margin-bottom: 1rem; }
.alerta-ok { background: var(--okb); color: var(--ok); border-color: var(--ok); }
.alerta-aviso { background: var(--wab); color: var(--wa); border-color: var(--wa); }
.alerta-error { background: var(--crb); color: var(--cr); border-color: var(--cr); }

/* Pills de estado: color + texto */
.pill {
    display: inline-flex; align-items: center; gap: .3rem;
    padding: .15rem .6rem; border-radius: 999px;
    font-size: .8125rem; font-weight: 600; line-height: 1.4; white-space: nowrap;
}
.pill-verde { background: var(--okb); color: var(--ok); }
.pill-ambar { background: var(--wab); color: var(--wa); }
.pill-rojo { background: var(--crb); color: var(--cr); }
.pill-azul { background: var(--infb); color: var(--inf); }
.pill-gris { background: var(--grb); color: var(--gr); }

/* Paneles y tarjetas */
.panel {
    background: var(--sf); border: 1px solid var(--ln); border-radius: var(--radio);
    padding: clamp(1rem, 3vw, 1.5rem); box-shadow: var(--sombra); margin-bottom: 1rem;
}
.panel-centro { max-width: 36rem; margin-inline: auto; text-align: center; display: grid; gap: .75rem; justify-items: center; }
.titulo-seccion { font-size: clamp(1.15rem, 1rem + 1vw, 1.5rem); margin-bottom: .5rem; }

.grilla-tarjetas { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 15rem), 1fr)); gap: 1rem; }
.grilla-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 22rem), 1fr)); gap: 1rem; align-items: start; }
.tarjeta {
    display: flex; gap: 1rem; align-items: flex-start;
    background: var(--sf); border: 1px solid var(--ln); border-radius: var(--radio);
    padding: 1rem 1.25rem; box-shadow: var(--sombra); color: var(--ink); text-decoration: none;
}
.tarjeta-link:hover { border-color: var(--pri); }
.tarjeta-icono { display: grid; place-items: center; width: 2.75rem; height: 2.75rem; border-radius: var(--radio-s); background: var(--prs); color: var(--pri); flex: none; }
.tarjeta-texto { display: grid; gap: .1rem; min-width: 0; }
.tarjeta-titulo { color: var(--ink2); font-weight: 600; }
.tarjeta-valor { font-size: clamp(1.75rem, 1.4rem + 1.5vw, 2.25rem); font-weight: 700; line-height: 1.15; font-family: var(--mono); }
.tarjeta-valor-vacio { font-size: 1.1rem; color: var(--ink2); font-family: var(--fuente); font-weight: 600; }
.tarjeta-detalle { color: var(--ink2); font-size: .875rem; }

/* Datos clave/valor */
.datos { display: grid; gap: .75rem; margin: 0; }
.datos dt { color: var(--ink2); font-size: .875rem; }
.datos dd { margin: 0; overflow-wrap: anywhere; }

/* Tablas */
.tabla-scroll { position: relative; overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--ln); border-radius: var(--radio-s); }
.tabla { width: 100%; border-collapse: collapse; min-width: 28rem; }
.tabla th, .tabla td { padding: .6rem .8rem; text-align: left; border-bottom: 1px solid var(--ln); vertical-align: top; }
.tabla thead th { background: var(--sf2); font-size: .875rem; }
.tabla tbody tr:last-child td { border-bottom: 0; }

/* Layout de la aplicación */
.shell { min-height: 100vh; display: block; }
.shell-main { min-width: 0; display: flex; flex-direction: column; min-height: 100vh; }
.contenido { flex: 1; width: 100%; max-width: 80rem; margin-inline: auto; padding: clamp(1rem, 3vw, 2rem) clamp(1rem, 3vw, 2rem) 2rem; outline: none; }
.pie { padding: 1rem; text-align: center; color: var(--ink2); font-size: .8125rem; }

.topbar {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; gap: .5rem; flex-wrap: wrap;
    padding: .5rem clamp(.75rem, 3vw, 1.5rem);
    background: var(--sf); border-bottom: 1px solid var(--ln);
}
.topbar-titulo { margin: 0; font-size: clamp(1.05rem, .95rem + .6vw, 1.35rem); flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.topbar-acciones { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

/* Menú lateral: drawer en móvil */
.sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 40;
    width: min(85vw, var(--lateral)); overflow-y: auto;
    background: var(--sf); border-right: 1px solid var(--ln);
    padding: 1rem .75rem; display: flex; flex-direction: column; gap: .5rem;
    transform: translateX(-105%); transition: transform .2s ease;
    visibility: hidden;
}
.shell.menu-abierto .sidebar { transform: none; visibility: visible; }
.shell-overlay { position: fixed; inset: 0; z-index: 30; background: rgba(0, 0, 0, .5); }
.shell-overlay[hidden] { display: none; }

.sidebar-cabecera { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: 0 .25rem .5rem; }
.marca { display: inline-flex; align-items: center; gap: .6rem; text-decoration: none; color: var(--ink); font-weight: 700; letter-spacing: .06em; }
.marca-logo { display: grid; place-items: center; width: 2.25rem; height: 2.25rem; border-radius: .6rem; background: var(--pri); color: var(--onpri); font-weight: 700; font-family: var(--mono); }
.marca-logo-grande { width: 3rem; height: 3rem; font-size: 1.5rem; }

.menu-grupo { margin-top: .5rem; }
.menu-titulo { margin: 0 0 .25rem; padding: 0 .75rem; font-size: .75rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--ink2); }
.menu-lista { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.menu-item {
    display: flex; align-items: center; gap: .75rem;
    min-height: var(--tactil); padding: .5rem .75rem; border-radius: var(--radio-s);
    color: var(--ink); text-decoration: none; font-weight: 500;
}
.menu-item span:not(.pill) { flex: 1; min-width: 0; }
a.menu-item:hover { background: var(--sf2); }
.menu-item[aria-current="page"] { background: var(--prs); color: var(--pri); font-weight: 700; box-shadow: inset 3px 0 0 var(--pri); }
.menu-item-off { color: var(--ink2); cursor: not-allowed; }

.sidebar-pie { margin-top: auto; padding-top: .75rem; border-top: 1px solid var(--ln); }
.usuario-chip { display: flex; align-items: center; gap: .75rem; min-height: var(--tactil); padding: .4rem .5rem; border-radius: var(--radio-s); color: var(--ink); text-decoration: none; }
.usuario-chip:hover { background: var(--sf2); }
.avatar { display: grid; place-items: center; width: 2.25rem; height: 2.25rem; border-radius: 50%; background: var(--prs); color: var(--pri); font-weight: 700; flex: none; }
.usuario-datos { display: grid; min-width: 0; }
.usuario-nombre { font-weight: 600; overflow-wrap: anywhere; }
.usuario-sub { color: var(--ink2); font-size: .8125rem; }

/* Tablet/escritorio: menú fijo */
@media (min-width: 64rem) {
    .shell { display: grid; grid-template-columns: var(--lateral) minmax(0, 1fr); }
    .sidebar { position: sticky; top: 0; height: 100vh; width: auto; transform: none; visibility: visible; }
    .shell-overlay, .sidebar-cerrar, .topbar-menu { display: none !important; }
}

/* Pantallas de acceso */
.acceso { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.acceso-caja { width: min(100%, 26rem); display: grid; gap: 1rem; justify-items: stretch; outline: none; }
.acceso-marca { display: flex; align-items: center; gap: .75rem; }
.acceso-nombre { margin: 0; font-size: 1.5rem; font-weight: 700; letter-spacing: .08em; }
.acceso-lema { margin: 0; color: var(--ink2); font-size: .875rem; }
.acceso-panel { margin: 0; }
.acceso-pie { margin: 0; color: var(--ink2); font-size: .8125rem; text-align: center; }
.acceso .btn-tema { justify-self: center; }

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; }
}

@media print {
    .sidebar, .topbar, .shell-overlay, .pie, .skip-link { display: none !important; }
    .shell { display: block; }
    body { background: #fff; color: #000; }
}
