/*
 * Panel y portal de Fakto. Los colores, la letra y los botones vienen de fakto.css (la marca de fakto.do).
 * Barra superior blanca de 60 px con la franja tricolor del isotipo, menú
 * negro de 248 px, cabecera de página blanca (rótulo + título + subtítulo) y
 * el contenido sobre el gris hundido.
 *
 * Plataforma web actual, sin compilar y sin librerías:
 *   anidación nativa · :has() · consultas de contenedor
 *   popover (menú móvil sin JS) · <dialog> (confirmaciones)
 *   View Transitions entre páginas · @starting-style (animaciones de entrada)
 */

@view-transition { navigation: auto; }

@layer componentes {

    /* ─── Botones (sf-btn) ────────────────────────────────────────────── */
    /* Por defecto, primario: azul de acción. .acento: verde de marca. .secundario: contorno. */
    button, .boton {
        --b-fondo: var(--sg-primario);
        --b-borde: var(--sg-primario);
        --b-texto: #fff;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        min-height: 40px;
        padding: 10px 16px;
        border: 1px solid var(--b-borde);
        border-radius: var(--sg-r-sm);
        background: var(--b-fondo);
        color: var(--b-texto);
        font: 600 .875rem/1 var(--sg-titulos);
        white-space: nowrap;
        text-decoration: none;
        cursor: pointer;
        transition: background var(--sg-t), border-color var(--sg-t), color var(--sg-t), translate var(--sg-t);

        &:hover { --b-fondo: var(--sg-primario-hover); --b-borde: var(--sg-primario-hover); }
        &:active { translate: 0 1px; }
        &:disabled { opacity: .5; cursor: not-allowed; }
        & svg { width: 16px; height: 16px; flex: none; }

        &.acento {
            --b-fondo: var(--sg-verde-boton);
            --b-borde: var(--sg-verde-boton);
            &:hover { --b-fondo: var(--sg-verde-hover); --b-borde: var(--sg-verde-hover); }
        }
        &.secundario {
            --b-fondo: var(--papel);
            --b-borde: var(--linea);
            --b-texto: var(--fuerte);
            &:hover { --b-fondo: var(--papel); --b-borde: var(--sg-acento); --b-texto: var(--enlace); }
        }
        &.peligro {
            --b-fondo: var(--papel);
            --b-borde: color-mix(in oklab, var(--mal) 35%, var(--linea));
            --b-texto: var(--mal);
            &:hover { --b-fondo: var(--mal-f); --b-borde: var(--mal); }
        }
        &.enlace {
            min-height: 0;
            padding: 0;
            border: 0;
            background: none;
            color: var(--enlace);
            font: 500 .875rem/1.4 var(--sg-texto);
            &:hover { text-decoration: underline; }
        }
        &.icono {
            --b-fondo: transparent;
            --b-borde: var(--linea);
            --b-texto: var(--tenue);
            width: 34px;
            min-height: 34px;
            padding: 0;
            &:hover { --b-fondo: var(--papel-2); --b-texto: var(--fuerte); }
            & svg { width: 18px; height: 18px; }
        }
    }

    /* ─── Formularios (sf-input) ──────────────────────────────────────── */
    label {
        display: grid;
        gap: 6px;
        & > span { font-size: .8125rem; font-weight: 600; color: var(--fuerte); }
        & > small { font-size: .75rem; color: var(--tenue); }
        &:has(:required) > span::after { content: " *"; color: var(--sg-acento); }
    }
    input, select, textarea {
        width: 100%;
        min-height: 40px;
        padding: 8px 12px;
        border: 1px solid var(--linea-fuerte);
        border-radius: var(--sg-r-sm);
        background: var(--papel);
        color: var(--fuerte);
        font-size: .875rem;
        box-shadow: var(--sg-shadow-sm);
        transition: border-color var(--sg-t), box-shadow var(--sg-t);

        &::placeholder { color: var(--sg-gris-400); }
        &:focus { outline: none; border-color: var(--sg-acento); box-shadow: var(--sg-focus); }
        &:user-invalid { border-color: var(--mal); }
    }
    input[type="file"] { padding: 6px; }
    label.check {
        display: flex;
        gap: 10px;
        align-items: center;
        & > span { font-weight: 400; color: var(--tinta); }
        & input { width: 18px; min-height: 18px; padding: 0; box-shadow: none; accent-color: var(--sg-acento); }
    }
    input[type="file"]::file-selector-button {
        margin-right: 10px;
        padding: 6px 12px;
        border: 0;
        border-radius: var(--sg-r-sm);
        background: var(--hielo);
        color: var(--titulo);
        font: 600 .8rem/1.2 var(--sg-titulos);
        cursor: pointer;
    }
    textarea {
        min-height: 280px;
        max-height: 70vh;
        font-family: var(--sg-mono);
        font-size: .8rem;
        line-height: 1.55;
        field-sizing: content;
    }

    form.apilado { display: grid; gap: 16px; }
    form.en-linea { display: inline; }
    .fila {
        /* Alineada por arriba: la etiqueta ocupa siempre la misma altura y la
           ayuda (si hay) cuelga debajo sin mover a los vecinos ni al botón. */
        --alto-etiqueta: calc(.8125rem * 1.2 + 6px);
        display: flex;
        flex-wrap: wrap;
        gap: 12px;
        align-items: start;
        & > label { flex: 1 1 170px; }
        & > label > span { line-height: 1.2; }
        /* Botones (y enlaces con botón) a la altura del campo, no de la etiqueta. */
        &:has(> label > span) > :is(button, a, .en-linea) { margin-top: var(--alto-etiqueta); }
        &:has(> label > span) > label.check { flex: 0 0 auto; margin-top: var(--alto-etiqueta); min-height: 40px; }
        & > :is(button, a, .en-linea) { align-self: start; }
    }
    .fila.arriba { align-items: start; }
    .fila.compacto { gap: 8px; }
    /* Resultado de la consulta del RNC en la DGII (alta de empresa). */
    .padron {
        margin-top: -6px;
        padding: 10px 14px;
        border-radius: var(--sg-r-sm);
        background: var(--papel-2);
        color: var(--tinta);
        font-size: .875rem;
        &.ok { background: var(--ok-f); color: var(--ok); }
        &.aviso { background: var(--aviso-f); color: var(--aviso); }
        & b { color: inherit; }
    }

    /* ─── Tarjetas (sf-card) ──────────────────────────────────────────── */
    .tarjeta {
        --relleno: 20px;
        container-type: inline-size;
        margin-bottom: 20px;
        padding: var(--relleno);
        background: var(--papel);
        border: 1px solid var(--linea);
        border-radius: var(--sg-r-md);
        box-shadow: var(--sg-shadow-sm);

        /* Título de tarjeta con su línea, como sf-card-head */
        & > h2:first-child, & > .cabeza:first-child {
            margin: calc(var(--relleno) * -1) calc(var(--relleno) * -1) var(--relleno);
            padding: 16px var(--relleno);
            border-bottom: 1px solid var(--linea);
        }
        & > .cabeza:first-child { align-items: center; & h2 { margin: 0; } }

        /* Las tablas van de borde a borde */
        & > .tabla-envoltura {
            margin-inline: calc(var(--relleno) * -1);
            & :is(th, td):first-child { padding-left: var(--relleno); }
            & :is(th, td):last-child { padding-right: var(--relleno); }
            &:last-child { margin-bottom: calc(var(--relleno) * -1); & tr:last-child td { border-bottom: 0; } }
            &:first-child { margin-top: calc(var(--relleno) * -1); }
        }
        & > h2:first-child + .tabla-envoltura { margin-top: calc(var(--relleno) * -1); }
        & > :is(p, form, dl, ul, ol) + :is(p, form) { margin-top: 12px; }
        & > p:last-child:has(> a) { margin-top: 14px; font-size: .875rem; font-weight: 600; }
    }

    /* ─── Cifras (sf-stat) ────────────────────────────────────────────── */
    .rejilla {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(168px, 1fr));
        gap: 16px;
        margin-bottom: 20px;
    }
    .dato {
        display: flex;
        flex-direction: column-reverse;   /* etiqueta arriba, cifra abajo */
        justify-content: flex-end;
        gap: 4px;
        padding: 16px;
        background: var(--papel);
        border: 1px solid var(--linea);
        border-radius: var(--sg-r-md);
        box-shadow: var(--sg-shadow-sm);
        & span {
            color: var(--tenue);
            font-size: .6875rem;
            font-weight: 600;
            letter-spacing: .06em;
            text-transform: uppercase;
        }
        & b {
            color: var(--titulo);
            font: 700 1.5rem/1.15 var(--sg-texto);
            letter-spacing: -.01em;
            font-variant-numeric: tabular-nums;
        }
        &.alerta {
            border-color: color-mix(in oklab, var(--mal) 30%, var(--linea));
            background: var(--mal-f);
            & b { color: var(--mal); }
        }
    }

    .dos {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr));
        gap: 20px;
        align-items: start;
        margin-bottom: 20px;
        & > .tarjeta { margin-bottom: 0; }
    }

    /* ─── Tablas ──────────────────────────────────────────────────────── */
    .tabla-envoltura { overflow-x: auto; overscroll-behavior-x: contain; }
    table {
        width: 100%;
        border-collapse: separate;
        border-spacing: 0;
        font-size: .875rem;
        font-variant-numeric: tabular-nums;
    }
    th {
        padding: 10px 14px;
        background: var(--papel-2);
        border-bottom: 1px solid var(--linea);
        color: var(--tenue);
        font-size: .6875rem;
        font-weight: 600;
        letter-spacing: .06em;
        text-align: left;
        text-transform: uppercase;
        white-space: nowrap;
    }
    td {
        padding: 12px 14px;
        border-bottom: 1px solid var(--linea);
        vertical-align: top;
        color: var(--tinta);
        & b { color: var(--fuerte); }
        & a b { color: var(--titulo); }
        /* RNC, e-NCF y montos en mono, como pide el sistema */
        & .mono { color: var(--fuerte); }
    }
    tbody tr { transition: background var(--sg-t); }
    tbody tr:hover { background: color-mix(in oklab, var(--sg-acento) 4%, transparent); }
    .vacio {
        padding: 28px 16px;
        border: 1px dashed var(--linea-fuerte);
        border-radius: var(--sg-r-md);
        color: var(--tenue);
        text-align: center;
        font-size: .875rem;
    }

    /* ─── Chips (sf-chip) ─────────────────────────────────────────────── */
    .chip {
        --c: var(--tinta);
        --f: var(--papel-2);
        display: inline-flex;
        align-items: center;
        gap: 6px;
        padding: 2px 10px;
        border: 1px solid transparent;
        border-radius: 999px;
        background: var(--f);
        color: var(--c);
        font-size: .75rem;
        font-weight: 600;
        line-height: 1.5;
        white-space: nowrap;
        vertical-align: middle;
        &::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
        &.neutro { border-color: var(--linea); }
        &.ok { --c: var(--ok); --f: var(--ok-f); }
        &.aviso { --c: var(--aviso); --f: var(--aviso-f); }
        &.mal { --c: var(--mal); --f: var(--mal-f); }
        &.info { --c: var(--info); --f: var(--info-f); }
    }
    .amb {
        display: inline-block;
        padding: 3px 8px;
        border-radius: var(--sg-r-sm);
        background: var(--papel-2);
        color: var(--tenue);
        font: 500 .6875rem/1.3 var(--sg-mono);
        letter-spacing: .04em;
        text-transform: uppercase;
        white-space: nowrap;
    }
    .amb-certificacion { background: var(--aviso-f); color: var(--aviso); }
    .amb-produccion { background: var(--hielo); color: var(--titulo); font-weight: 600; }

    /* ─── Avisos (sf-banner) ──────────────────────────────────────────── */
    .flash {
        --c: var(--info);
        --f: var(--info-f);
        display: flex;
        gap: 12px;
        align-items: center;
        margin-bottom: 20px;
        padding: 12px 16px;
        border-radius: var(--sg-r-sm);
        background: var(--f);
        color: var(--c);
        font-size: .875rem;
        font-weight: 500;
        transition: opacity .3s, translate .3s;
        @starting-style { opacity: 0; translate: 0 -6px; }
        &::before {
            content: "";
            flex: none;
            width: 8px;
            height: 8px;
            border-radius: 50%;
            background: currentColor;
            box-shadow: 0 0 0 4px color-mix(in oklab, currentColor 18%, transparent);
        }
        &.ok { --c: var(--ok); --f: var(--ok-f); }
        &.mal { --c: var(--mal); --f: var(--mal-f); }
        &.aviso { --c: var(--aviso); --f: var(--aviso-f); }
    }

    /* ─── Llaves que se muestran una sola vez ─────────────────────────── */
    .secreto {
        position: relative;
        margin: 10px 0;
        padding: 14px 52px 14px 16px;
        border-radius: var(--sg-r-md);
        background: var(--sg-negro);
        color: var(--sg-azul-claro);
        font: 500 .85rem/1.5 var(--sg-mono);
        word-break: break-all;
        & .copiar {
            position: absolute;
            top: 8px;
            right: 8px;
            width: 34px;
            min-height: 32px;
            padding: 0;
            border: 1px solid rgb(77 179 234 / .3);
            background: rgb(255 255 255 / .06);
            color: var(--sg-azul-claro);
            &:hover, &.hecho { background: rgb(0 129 198 / .25); }
        }
    }

    /* ─── Varios ──────────────────────────────────────────────────────── */
    .sub { margin-top: 4px; color: var(--tenue); font-size: .875rem; max-width: 75ch; }
    .tenue { color: var(--tenue); }
    .mono { font-family: var(--sg-mono); }
    .eyebrow {
        color: var(--eyebrow);
        font: 600 .6875rem/1.4 var(--sg-titulos);
        letter-spacing: .12em;
        text-transform: uppercase;
    }
    dl {
        display: grid;
        grid-template-columns: max-content 1fr;
        gap: 10px 24px;
        font-size: .875rem;
        & dt { color: var(--tenue); }
        & dd { margin: 0; min-width: 0; overflow-wrap: anywhere; color: var(--fuerte); }
    }
    pre {
        max-height: 440px;
        overflow: auto;
        padding: 14px 16px;
        border: 1px solid var(--linea);
        border-radius: var(--sg-r-md);
        background: var(--papel-2);
        color: var(--fuerte);
        font-size: .78rem;
        line-height: 1.6;
    }
    .cabeza {
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;
        align-items: start;
        gap: 12px 16px;
        margin-bottom: 20px;
        & .acciones { display: flex; flex-wrap: wrap; gap: 8px; }
    }
    /* Barra de contexto: empresa · ambiente · mes, arriba de las páginas por empresa. */
    .contexto {
        display: flex;
        flex-wrap: wrap;
        align-items: end;
        gap: 10px 18px;
        margin-bottom: 20px;
        padding: 12px 16px;
        background: var(--papel);
        border: 1px solid var(--linea);
        border-radius: var(--sg-r-md);
        box-shadow: var(--sg-shadow-sm);
        & > label, & > .fija, & > .mes { display: grid; gap: 4px; }
        & > label { flex: 1 1 220px; max-width: 420px; }
        & > label > span, & > .fija > span, & > .mes > span:first-child { font-size: .6875rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--tenue); }
        & select { min-height: 36px; padding: 6px 10px; }
        & .fija b, & .mes b { font-size: .9375rem; color: var(--fuerte); line-height: 36px; white-space: nowrap; }
        & .mes { grid-template-columns: 36px auto 36px; align-items: center; column-gap: 8px; }
        & .mes > span:first-child { grid-column: 1 / -1; }
        & .mes > b { text-align: center; min-width: 9em; }
        & .flecha {
            width: 36px; min-height: 36px; line-height: 36px; text-align: center;
            border: 1px solid var(--linea-fuerte); border-radius: var(--sg-r-sm); color: var(--titulo); font-weight: 700; text-decoration: none;
            &:hover { background: var(--papel-2); }
            &.vacia { color: var(--sg-gris-400); border-color: var(--linea); }
        }
    }
    .tarjeta > .acciones, .acciones-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
    .acciones-form { margin: 4px 0 20px; }
    /* Facturar desde la PC: renglones compactos en tabla. */
    table.renglones {
        & td { padding: 6px 8px; vertical-align: middle; }
        & .quitar-renglon {
            width: 30px; height: 30px; min-height: 30px; padding: 0;
            border: 1px solid transparent; border-radius: var(--sg-r-sm);
            background: transparent; color: var(--tenue); cursor: pointer; font-size: .875rem;
            &:hover { border-color: var(--linea); color: var(--peligro, #c0392b); }
        }
        & td:first-child { width: 46%; }
        & input:not([type="checkbox"]) { min-height: 36px; padding: 6px 10px; }
        & input[type="checkbox"] { width: 18px; min-height: 18px; accent-color: var(--sg-acento); box-shadow: none; }
        & .centro { text-align: center; }
        /* En el teléfono cada renglón es una tarjetita: descripción arriba, cantidad y precio, y las casillas. */
        @media (max-width: 640px) {
            & thead { display: none; }
            & tr { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; padding: 12px 20px; border-bottom: 1px solid var(--linea); }
            & td { display: grid; gap: 2px; padding: 0 !important; border: 0; width: auto !important; text-align: left; }
            & td::before { content: attr(data-etq); font-size: .6875rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--tenue); }
            & td:first-child { grid-column: 1 / -1; }
            & td.centro { grid-template-columns: auto 1fr; justify-items: start; align-items: center; column-gap: 8px; text-align: left !important; }
            & td.centro::before { order: 2; }
            & td:last-child { position: absolute; right: 12px; top: 8px; }
            & td:last-child::before { content: none; }
            & tr { position: relative; }
            & td:first-child { padding-right: 38px !important; }
        }
    }
    /* Bancos: casillas de formas de pago; mover una línea de cuenta. */
    .casillas { display: flex; flex-wrap: wrap; gap: 6px 18px; align-items: center; & .etq { width: 100%; font-size: .8125rem; font-weight: 600; } }
    form.mover { gap: 6px; flex-wrap: nowrap; & select { min-height: 30px; padding: 2px 6px; font-size: .8125rem; max-width: 150px; } }
    /* Por cobrar: el formulario de cobro se abre dentro de la fila. */
    details.cobrar {
        & summary { cursor: pointer; color: var(--sg-acento); font-weight: 600; font-size: .8125rem; white-space: nowrap; }
        &[open] summary { margin-bottom: 8px; }
        & form { min-width: 220px; gap: 8px; }
        & input, & select { min-height: 34px; }
    }
    a.dato-enlace { text-decoration: none; color: inherit; display: block; & .dato:hover { border-color: var(--linea-fuerte); } }

    /* Configuración: campos a dos columnas; el "quitar" de un secreto pegado a su campo. */
    .dos.campos { gap: 16px 20px; margin-bottom: 16px; }
    .campo-secreto { display: grid; gap: 8px; }
    /* Páginas de una lista larga: ← más recientes · 51–100 de 312 · más antiguos → */
    .paginador {
        display: flex;
        align-items: center;
        gap: 12px;
        font-size: .8125rem;
        & > span:empty { min-width: 0; }
    }
    .tarjeta > .pie-tabla { display: flex; justify-content: flex-end; padding-top: 14px; }
    ol.pasos {
        display: grid;
        gap: 14px;
        margin: 0 0 16px;
        padding: 0;
        list-style: none;
        counter-reset: paso;
        & > li {
            position: relative;
            padding-left: 40px;
            counter-increment: paso;
            &::before {
                content: counter(paso);
                position: absolute;
                left: 0;
                top: -2px;
                display: grid;
                place-items: center;
                width: 28px;
                height: 28px;
                border-radius: 50%;
                background: var(--sg-avatar);
                color: #fff;
                font: 700 .8rem/1 var(--sg-titulos);
            }
        }
    }

    /* Salud del servicio (tablero) */
    .salud {
        --c: var(--ok);
        border-left: 3px solid var(--c);
        & > h2:first-child { display: flex; align-items: center; gap: 10px; }
        & > h2:first-child::before {
            content: "";
            width: 9px;
            height: 9px;
            border-radius: 50%;
            background: var(--c);
            box-shadow: 0 0 0 4px color-mix(in oklab, var(--c) 18%, transparent);
        }
        &.salud-aviso { --c: var(--aviso); }
        &.salud-problema { --c: var(--mal); }
    }
    ul.hallazgos {
        list-style: none;
        padding: 0;
        & li { display: flex; gap: 10px; align-items: baseline; padding: 9px 0; border-bottom: 1px solid var(--linea); font-size: .875rem; }
        & li:last-child { border-bottom: 0; }
    }

    /* ─── Confirmación (<dialog>) ─────────────────────────────────────── */
    dialog.confirmar {
        margin: auto;   /* el reset pone margin: 0 y el diálogo dejaba de centrarse */
        width: min(92vw, 420px);
        padding: 24px;
        border: 1px solid var(--linea);
        border-radius: var(--sg-r-lg);
        background: var(--papel);
        color: var(--tinta);
        box-shadow: var(--sg-shadow-lg);
        transition: opacity .18s, scale .18s, overlay .18s allow-discrete, display .18s allow-discrete;
        @starting-style { opacity: 0; scale: .97; }
        &:not([open]) { opacity: 0; scale: .97; }
        &::backdrop { background: rgb(0 18 70 / .4); backdrop-filter: blur(2px); }
        & h2 { margin-bottom: 6px; font-size: 1.05rem; }
        & p { font-size: .9rem; }
        & .botones { display: flex; justify-content: end; gap: 10px; margin-top: 22px; }
    }
}

@layer pagina {

    /* ─── Estructura: barra · menú · área ─────────────────────────────── */
    body.con-menu {
        display: grid;
        grid-template: "barra" 60px "area" 1fr / minmax(0, 1fr);
        @media (width >= 1024px) {
            grid-template: "barra barra" 60px "menu area" 1fr / 248px minmax(0, 1fr);
        }
    }

    .barra {
        grid-area: barra;
        position: sticky;
        top: 0;
        z-index: 20;
        display: flex;
        align-items: center;
        gap: 14px;
        padding: 0 16px;
        background: color-mix(in oklab, var(--papel) 92%, transparent);
        backdrop-filter: saturate(1.4) blur(10px);
        border-bottom: 1px solid var(--linea);
        @media (width >= 640px) { padding: 0 24px; }
        /* Franja verde · azul · rojo del isotipo. */
        &::before {
            content: "";
            position: absolute;
            inset: 0 0 auto;
            height: 3px;
            background: var(--sg-franja);
        }

        & .abrir-menu { @media (width >= 1024px) { display: none; } }
        & .der { margin-left: auto; display: flex; align-items: center; gap: 10px; }
        & .separador { width: 1px; height: 28px; background: var(--linea); }
    }

    .marca {
        display: flex;
        align-items: center;
        gap: 10px;
        text-decoration: none;
        & img { width: 36px; height: auto; flex: none; }
        & .nombre { display: grid; line-height: 1.05; }
        /* «saedi» como en el logotipo; debajo, el rótulo en Aaargh con tracking 800. */
        & b { color: var(--titulo); font: 700 1.125rem/1 var(--sg-titulos); letter-spacing: -.01em; }
        & small {
            color: var(--eyebrow);
            font: 400 .625rem/1.6 var(--sg-rotulo);
            letter-spacing: .5em;
            text-transform: uppercase;
        }
    }

    .quien {
        display: flex;
        align-items: center;
        gap: 8px;
        padding: 4px 8px;
        border-radius: var(--sg-r-sm);
        color: var(--tinta);
        text-decoration: none;
        transition: background var(--sg-t);
        &:hover, &[aria-current="page"] { background: var(--papel-2); }
        & .avatar {
            display: grid;
            place-items: center;
            width: 30px;
            height: 30px;
            border-radius: 50%;
            background: var(--sg-avatar);
            color: #fff;
            font: 700 .75rem/1 var(--sg-titulos);
        }
        & .datos { display: none; line-height: 1.25; @media (width >= 640px) { display: grid; } }
        & b { color: var(--fuerte); font-size: .8125rem; font-weight: 600; }
        & small { color: var(--tenue); font-size: .6875rem; }
        & small.falta { color: var(--aviso); font-weight: 600; }
    }

    /* Menú negro (el negro de la marca) */
    .menu {
        grid-area: menu;
        display: flex;
        flex-direction: column;
        padding: 10px 12px;
        background: var(--menu);
        color: #fff;

        & .grupo {
            padding: 9px 12px 3px;
            color: #8b95a3;
            font-size: .625rem;
            font-weight: 700;
            letter-spacing: .14em;
            text-transform: uppercase;
            &:first-child { padding-top: 4px; }
        }
        & a {
            display: flex;
            align-items: center;
            gap: 12px;
            margin-bottom: 1px;
            padding: 4px 12px;
            line-height: 1.25;
            border-radius: var(--sg-r-sm);
            color: #c9d1db;
            font-size: .875rem;
            font-weight: 500;
            text-decoration: none;
            transition: background var(--sg-t), color var(--sg-t);
            & svg { width: 18px; height: 18px; flex: none; }
            &:hover { background: rgb(255 255 255 / .07); color: #fff; }
            &[aria-current="page"] {
                background: rgb(0 129 198 / .24);
                color: #fff;
                font-weight: 600;
                & svg { color: var(--sg-azul-claro); }
            }
        }
        & .pie {
            margin-top: auto;
            /* En pantallas bajas el pie (versión/ambiente) cede su sitio al menú. */
            @media (height < 820px) { display: none; }
            padding: 12px;
            border-radius: var(--sg-r-md);
            background: rgb(0 0 0 / .2);
            font-size: .6875rem;
            color: rgb(111 220 255 / .85);
            & div { display: flex; justify-content: space-between; gap: 8px; }
            & b { color: #fff; font-family: var(--sg-mono); font-weight: 500; }
        }

        /* Escritorio: columna fija bajo la barra (se anula el popover). */
        @media (width >= 1024px) {
            &[popover] {
                position: sticky;
                top: 60px;
                inset: auto;
                width: auto;
                height: calc(100dvh - 60px);
                margin: 0;
                border: 0;
                overflow-y: auto;
                color: #fff;
            }
            &[popover]:not(:popover-open) { display: flex; }
        }
        /* Móvil: cajón desde la izquierda, bajo la barra. */
        @media (width < 1024px) {
            &[popover] {
                inset: 60px auto 0 0;
                width: 260px;
                height: calc(100dvh - 60px);
                margin: 0;
                border: 0;
                color: #fff;
                box-shadow: var(--sg-shadow-lg);
                transition: translate .22s, overlay .22s allow-discrete, display .22s allow-discrete;
                @starting-style { translate: -100% 0; }
            }
            &[popover]:not(:popover-open) { translate: -100% 0; }
            &::backdrop { background: rgb(0 0 0 / .4); }
        }
    }

    .area { grid-area: area; min-width: 0; display: flex; flex-direction: column; }

    /* Cabecera de página (eyebrow + título + subtítulo + acciones) */
    .cabecera-pagina {
        view-transition-name: cabecera;
        padding: 18px 16px;
        background: var(--papel);
        border-bottom: 1px solid var(--linea);
        @media (width >= 640px) { padding: 22px 32px; }
        & .cabeza { margin: 0; }
        & h1.mono { font-family: var(--sg-mono); font-weight: 500; letter-spacing: 0; }
        & .eyebrow { margin-bottom: 4px; }
    }

    main.contenido {
        view-transition-name: contenido;
        flex: 1;
        width: 100%;
        max-width: 1280px;
        padding: 20px 16px 64px;
        @media (width >= 640px) { padding: 28px 32px 64px; }
    }

    /* ─── Entrada (sin sesión): fondo negro de la marca ────────────────── */
    body.acceso {
        display: grid;
        grid-template-columns: 1fr;
        @media (width >= 1024px) { grid-template-columns: minmax(400px, 45%) 1fr; }
    }
    .acceso-marca {
        position: relative;
        overflow: hidden;
        display: flex;
        flex-direction: column;
        gap: 40px;
        justify-content: space-between;
        padding: clamp(24px, 5vw, 56px);
        background: var(--sg-hero);
        color: #d5dbe3;
        &::after {
            /* trama sutil */
            content: "";
            position: absolute;
            inset: 0;
            background-image: url("data:image/svg+xml,%3Csvg width='40' height='40' viewBox='0 0 40 40' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='%23ffffff' fill-opacity='0.06' fill-rule='evenodd'%3E%3Cpath d='M0 38.59l2.83-2.83 1.41 1.41L1.41 40H0v-1.41zM0 1.4l2.83 2.83 1.41-1.41L1.41 0H0v1.41zM38.59 40l-2.83-2.83 1.41-1.41L40 38.59V40h-1.41zM40 1.41l-2.83 2.83-1.41-1.41L38.59 0H40v1.41zM20 18.6l2.83-2.83 1.41 1.41L21.41 20l2.83 2.83-1.41 1.41L20 21.41l-2.83 2.83-1.41-1.41L18.59 20l-2.83-2.83 1.41-1.41L20 18.59z'/%3E%3C/g%3E%3C/svg%3E");
            pointer-events: none;
        }
        & > * { position: relative; z-index: 1; }
        & .logo { width: 180px; height: auto; }
        & .eyebrow { color: var(--sg-azul-claro); margin-bottom: 14px; }
        & h2 {
            max-width: 15ch;
            color: #fff;
            font-size: clamp(1.75rem, 1.2rem + 1.8vw, 3rem);
            font-weight: 700;
            font-style: italic;
            line-height: 1.1;
            letter-spacing: -.02em;
        }
        & p { margin-top: 16px; max-width: 44ch; color: #b7c0cc; }
        & ul {
            display: grid;
            gap: 12px;
            margin-top: 28px;
            padding: 0;
            list-style: none;
            & li { display: flex; gap: 10px; align-items: center; font-size: .9rem; }
            & svg { width: 18px; height: 18px; flex: none; color: var(--sg-verde-claro); }
        }
        & footer { color: #8b95a3; font-size: .75rem; }

        @media (width < 1024px) {
            gap: 18px;
            & ul, & p, & footer { display: none; }
            & h2 { font-size: 1.5rem; max-width: none; }
        }
    }
    main.acceso-form {
        display: grid;
        grid-template-columns: min(100%, 400px);
        place-content: center;
        padding: clamp(24px, 5vw, 56px) 20px;
        background: var(--fondo);
        & .tarjeta {
            padding: 32px;
            border-radius: var(--sg-r-lg);
            box-shadow: var(--sg-shadow-md);
            & h1 { margin: 0; padding: 0; border: 0; font-size: 1.5rem; }
            & .sub { margin: 4px 0 24px; }
            & button:not(.enlace) { width: 100%; min-height: 44px; }
        }
    }

    /* ─── Instalador web (/instalar): una columna, sin menú ────────────── */
    body.instalador { background: var(--fondo); }
    .instalador-cabeza {
        display: flex;
        gap: 12px;
        align-items: center;
        padding: 14px 20px;
        background: var(--menu);
        color: #fff;
        border-bottom: 4px solid transparent;
        border-image: var(--sg-franja) 1;
        & img { width: 40px; height: auto; }
        & span { display: grid; line-height: 1.1; }
        & b { font: 700 italic 1.35rem var(--sg-titulos); }
        & small { color: #9aa4b2; font-size: .75rem; }
    }
    .instalador-main {
        max-width: 880px;
        margin-inline: auto;
        padding: 24px 16px 64px;
        & > .cabeza { margin-bottom: 20px; }
        & .tarjeta h2 { margin-bottom: 10px; }
        & .tarjeta p + p, & .tarjeta p + .tabla-envoltura, & .tarjeta .tabla-envoltura + p { margin-top: 10px; }
        & form.apilado { max-width: 420px; margin-top: 12px; }
        & .secreto { margin: 0; }
        & .secreto pre { margin: 0; font: inherit; white-space: pre-wrap; }
    }

    ::view-transition-old(contenido), ::view-transition-old(cabecera) { animation: 120ms ease-in both vt-salir; }
    ::view-transition-new(contenido), ::view-transition-new(cabecera) { animation: 200ms cubic-bezier(.2, .7, .2, 1) both vt-entrar; }
    @keyframes vt-salir { to { opacity: 0; } }
    @keyframes vt-entrar { from { opacity: 0; translate: 0 4px; } }
}

@layer utilidades {
    .mt-s { margin-top: 8px; }
    .mt { margin-top: 14px; }
    .mt-l { margin-top: 20px; }
    .mb-s { margin-bottom: 8px; }
    .oculto-visual {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip-path: inset(50%);
        white-space: nowrap;
    }
    @media (prefers-reduced-motion: reduce) {
        *, *::before, *::after { animation-duration: 1ms !important; transition-duration: 1ms !important; }
        ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
    }
}

/* Libro de compras: el formulario de clasificar dentro de la celda. */
form.apilado.compacto { gap: 6px; min-width: 220px; }
form.apilado.compacto label span { font-size: 12px; }
form.apilado.compacto select, form.apilado.compacto input { padding: 4px 6px; font-size: 13px; }

/* Logo de la empresa en su ficha. */
.logo-empresa { max-height: 80px; max-width: 240px; background: #fff; padding: 6px; border: 1px solid var(--borde, #ddd); border-radius: 6px; }

/* IT-1: casillas del papel de trabajo. */
table.casillas { width: 100%; border-collapse: collapse; }
table.casillas th { text-align: left; font-weight: 400; padding: 5px 6px; border-bottom: 1px solid var(--borde, #e3e3e3); }
table.casillas td.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; padding: 5px 6px; border-bottom: 1px solid var(--borde, #e3e3e3); }
table.casillas tr.fuerte th, table.casillas tr.fuerte td { font-weight: 700; border-top: 2px solid currentColor; }
@media print { .menu, .cabeza .acciones, form.fila.tarjeta, nav, header.barra { display: none !important; } }

/* Contabilidad */
nav.pestanas { display: flex; flex-wrap: wrap; gap: 4px; margin: 0 0 12px; border-bottom: 1px solid var(--linea); }
nav.pestanas a { padding: 7px 12px; text-decoration: none; color: inherit; border-bottom: 2px solid transparent; margin-bottom: -1px; }
nav.pestanas a.activa { border-bottom-color: var(--fuerte); font-weight: 700; }
span.num { display: block; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.asiento { padding: 8px 0; border-bottom: 1px solid var(--linea); }
.asiento > .fila { gap: 10px; margin-bottom: 4px; }
