/* =============================================================================
 * Paquete común ASX · barra superior
 *
 * Autocontenida a propósito: no depende de Bootstrap, de CORK ni del CSS de
 * ninguna aplicación. Así el portal —que no carga Bootstrap— y Control —que sí—
 * dibujan exactamente la misma barra.
 *
 * La barra es BLANCA en las cuatro, con el contenido centrado y con tope de
 * ancho. El color de cada aplicación aparece en el avatar, en el botón
 * destacado, en el foco y en lo seleccionado, nunca en el fondo.
 *
 * Los desplegables son <details>/<summary> nativos: se abren y se cierran sin
 * una línea de JavaScript. El componente <asx-top> solo añade lo que el HTML no
 * sabe hacer (cerrar al hacer clic fuera, Escape, y el contador en vivo).
 *
 * Requiere tokens.css.
 * ========================================================================== */

.asxb,
.asxb *,
.asxb *::before,
.asxb *::after {
    box-sizing: border-box;
}

.asxb {
    position: sticky;
    top: 0;
    z-index: var(--asxb-barra-z);
    background: var(--asxb-fondo);
    color: var(--asxb-texto);
    border-bottom: 1px solid var(--asxb-borde);
    font-family: var(--asxb-fuente);
    font-size: var(--asxb-texto-base);
    line-height: var(--asxb-alto-linea);
}

.asxb-inner {
    display: flex;
    align-items: center;
    gap: var(--asxb-barra-hueco);
    min-height: var(--asxb-barra-alto);
    /* Centrada y con tope: la barra acompaña al contenido, no al borde de la
       pantalla. */
    max-width: var(--asxb-ancho);
    margin-inline: auto;
    padding-inline: var(--asxb-barra-lados);
}

/* --- Zona 1: la marca de la aplicación ----------------------------------- */

.asxb-marca {
    display: inline-flex;
    align-items: center;
    gap: var(--asxb-esp-2);
    flex: 0 0 auto;
    color: inherit;
    text-decoration: none;
    font-weight: 800;
}

.asxb-marca img {
    display: block;
    height: 28px;
    width: auto;
}

/* --- Zona 2: lo propio de cada aplicación -------------------------------- */

.asxb-propio {
    display: flex;
    align-items: center;
    gap: var(--asxb-esp-3);
    flex: 1 1 auto;
    min-width: 0;
}

/* --- Zona 3: el ecosistema. Idéntica en las cuatro. ---------------------- */

.asxb-eco {
    display: flex;
    align-items: center;
    gap: var(--asxb-esp-1);
    flex: 0 0 auto;
    margin-inline-start: auto;
}

/* --- Botones de la barra -------------------------------------------------- */

.asxb-boton,
.asxb-menu > summary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--asxb-esp-2);
    min-width: var(--asxb-toque);
    min-height: var(--asxb-toque);
    padding: 0 var(--asxb-esp-2);
    border: 0;
    border-radius: var(--asxb-radio-1);
    background: transparent;
    color: inherit;
    font: inherit;
    cursor: pointer;
    position: relative;
    transition: background var(--asxb-transicion);
}

.asxb-menu > summary {
    list-style: none;
}

.asxb-menu > summary::-webkit-details-marker {
    display: none;
}

.asxb-boton:hover,
.asxb-menu > summary:hover,
.asxb-menu[open] > summary {
    background: var(--asxb-fondo-tenue);
}

.asxb-boton:focus-visible,
.asxb-menu > summary:focus-visible,
.asxb a:focus-visible {
    outline: 2px solid var(--asx-marca);
    outline-offset: 2px;
}

.asxb svg {
    width: 20px;
    height: 20px;
    display: block;
    flex: 0 0 auto;
}

/* Contador de avisos sin leer. Sin número cuando aún no se sabe. */
.asxb-punto {
    position: absolute;
    top: 6px;
    inset-inline-end: 4px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: var(--asxb-radio-redondo);
    background: var(--asxb-error);
    color: #fff;
    font-size: 10px;
    font-weight: 800;
    line-height: 16px;
    text-align: center;
}

.asxb-punto:empty {
    min-width: 8px;
    width: 8px;
    height: 8px;
    padding: 0;
    top: 9px;
    inset-inline-end: 9px;
}

/* --- Avatar --------------------------------------------------------------- */

.asxb-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: var(--asxb-radio-redondo);
    background: var(--asx-marca);
    color: #fff;
    font-size: var(--asxb-texto-xs);
    font-weight: 800;
    overflow: hidden;
}

.asxb-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* --- Paneles desplegables ------------------------------------------------- */

.asxb-menu {
    position: relative;
}

.asxb-panel {
    position: absolute;
    top: calc(100% + 6px);
    inset-inline-end: 0;
    min-width: 280px;
    max-width: min(360px, calc(100vw - 2 * var(--asxb-barra-lados)));
    max-height: min(70vh, 520px);
    overflow-y: auto;
    padding: var(--asxb-esp-2);
    border: 1px solid var(--asxb-borde);
    border-radius: var(--asxb-radio-2);
    background: var(--asxb-fondo);
    color: var(--asxb-texto);
    box-shadow: var(--asxb-sombra-alta);
}

.asxb-panel h2 {
    margin: 0;
    padding: var(--asxb-esp-2) var(--asxb-esp-3);
    font-size: var(--asxb-texto-xs);
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--asxb-texto-tenue);
}

.asxb-panel a,
.asxb-panel button {
    display: flex;
    align-items: center;
    gap: var(--asxb-esp-3);
    width: 100%;
    padding: var(--asxb-esp-2) var(--asxb-esp-3);
    border: 0;
    border-radius: var(--asxb-radio-1);
    background: transparent;
    color: inherit;
    font: inherit;
    text-align: start;
    text-decoration: none;
    cursor: pointer;
}

.asxb-panel a:hover,
.asxb-panel button:hover {
    background: var(--asxb-fondo-tenue);
}

.asxb-sep {
    height: 1px;
    margin: var(--asxb-esp-2) 0;
    background: var(--asxb-borde);
}

/* --- Panel de aplicaciones ------------------------------------------------ */

.asxb-app-nombre {
    display: block;
    font-weight: 700;
}

.asxb-app-que {
    display: block;
    font-size: var(--asxb-texto-xs);
    color: var(--asxb-texto-tenue);
}

.asxb-panel a[aria-current="true"] {
    background: var(--asx-marca-suave);
}

/* --- Panel de avisos ------------------------------------------------------ */

.asxb-aviso {
    display: block;
    padding: var(--asxb-esp-3);
}

.asxb-aviso strong {
    display: block;
    font-size: var(--asxb-texto-sm);
}

.asxb-aviso p {
    margin: 2px 0 0;
    font-size: var(--asxb-texto-sm);
    color: var(--asxb-texto-tenue);
}

.asxb-aviso time {
    font-size: var(--asxb-texto-xs);
    color: var(--asxb-texto-tenue);
}

.asxb-aviso[data-leido="no"] {
    border-inline-start: 3px solid var(--asx-marca);
}

.asxb-de {
    display: inline-block;
    margin-inline-end: var(--asxb-esp-2);
    padding: 1px 6px;
    border-radius: var(--asxb-radio-redondo);
    background: var(--asxb-fondo-tenue);
    font-size: 10px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--asxb-texto-tenue);
}

.asxb-vacio {
    padding: var(--asxb-esp-5) var(--asxb-esp-3);
    text-align: center;
    font-size: var(--asxb-texto-sm);
    color: var(--asxb-texto-tenue);
}

/* --- Panel de cuenta ------------------------------------------------------ */

.asxb-quien {
    padding: var(--asxb-esp-3);
    border-bottom: 1px solid var(--asxb-borde);
    margin-bottom: var(--asxb-esp-2);
}

.asxb-quien strong {
    display: block;
}

.asxb-quien span {
    font-size: var(--asxb-texto-sm);
    color: var(--asxb-texto-tenue);
    word-break: break-word;
}

/* --- Interruptor de tema -------------------------------------------------- */

.asxb-tema .asxb-sol {
    display: none;
}

:root[data-theme="dark"] .asxb-tema .asxb-sol {
    display: block;
}

:root[data-theme="dark"] .asxb-tema .asxb-luna {
    display: none;
}

/* --- Sin JavaScript: el componente no está, y todo sigue funcionando ------ */

.asxb-solo-con-js {
    display: none;
}

asx-top:defined .asxb-solo-con-js {
    display: revert;
}

/* --- Móvil ---------------------------------------------------------------- */

@media (max-width: 640px) {
    .asxb-marca img {
        height: 24px;
    }

    .asxb-propio {
        display: none;
    }

    .asxb-panel {
        position: fixed;
        inset-inline: var(--asxb-esp-2);
        top: calc(var(--asxb-barra-alto) + var(--asxb-esp-2));
        max-width: none;
    }
}

/* --- Impresión: la barra no se imprime ------------------------------------ */

@media print {
    .asxb {
        display: none;
    }
}

/* =============================================================================
 * Piezas para la ZONA PROPIA
 *
 * No son obligatorias: las pone la aplicación que las necesite. Están aquí, y
 * no en el CSS de cada app, porque tres de las cuatro tienen buscador en la
 * barra y no hay razón para que se vean distintos.
 * ========================================================================== */

.asxb-buscar {
    display: flex;
    align-items: center;
    flex: 1 1 320px;
    max-width: 420px;
    min-width: 0;
    height: 36px;
    padding-inline-start: var(--asxb-esp-3);
    border: 1px solid var(--asxb-borde);
    border-radius: var(--asxb-radio-2);
    background: var(--asxb-fondo-tenue);
}

.asxb-buscar input {
    flex: 1 1 auto;
    min-width: 0;
    border: 0;
    background: transparent;
    color: var(--asxb-texto);
    font: inherit;
    font-size: var(--asxb-texto-sm);
}

.asxb-buscar input:focus {
    outline: none;
}

.asxb-buscar button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: var(--asxb-radio-2);
    background: transparent;
    color: var(--asxb-texto-tenue);
    cursor: pointer;
}

/* Botón principal de la zona propia: la acción que la app quiere destacar. */
.asxb .asxb-destacado {
    border: 0;
    border-radius: var(--asxb-radio-redondo);
    background: var(--asx-marca);
    color: var(--asx-marca-contraste);
    font-weight: 700;
    white-space: nowrap;
}

.asxb .asxb-destacado:hover {
    filter: brightness(1.12);
}

/* Enlaces sueltos de la zona propia. Los que llevan color propio (el
   destacado) se excluyen: si no, `inherit` les gana por especificidad y el
   texto sale del color de la barra sobre el fondo de la marca. */
.asxb-propio > a:not(.asxb-destacado) {
    color: inherit;
    text-decoration: none;
    white-space: nowrap;
}

.visually-hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

/* --- Selector de contexto (organización, red, sede…) --------------------- */

.asxb-org > summary {
    gap: var(--asxb-esp-2);
    padding-inline: var(--asxb-esp-2);
}

.asxb-org-quien {
    display: flex;
    flex-direction: column;
    line-height: 1.15;
    text-align: start;
}

.asxb-org-quien strong {
    font-size: var(--asxb-texto-sm);
}

.asxb-org-quien small {
    font-size: var(--asxb-texto-xs);
    opacity: 0.75;
}

.asxb-panel button[aria-current="true"] {
    background: var(--asx-marca-suave);
}

/* --- Medidor de consumo (créditos, cuota, almacenamiento…) --------------- */

.asxb-creditos {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 130px;
    color: inherit;
    text-decoration: none;
    font-size: var(--asxb-texto-xs);
    opacity: 0.9;
}

.asxb-barrita {
    display: block;
    height: 5px;
    border-radius: var(--asxb-radio-redondo);
    background: var(--asxb-borde);
    overflow: hidden;
}

.asxb-barrita > span {
    display: block;
    height: 100%;
    background: var(--asx-marca);
}

.asxb-barrita > span[data-alto="si"] {
    background: var(--asxb-aviso);
}

@media (max-width: 1100px) {
    .asxb-creditos,
    .asxb-org-quien {
        display: none;
    }
}

/* Logotipo con versión para cada tema (`marca.logo_oscuro`). */
.asxb .asxb-logo-oscuro { display: none; }
:root[data-theme="dark"] .asxb .asxb-logo-claro { display: none; }
:root[data-theme="dark"] .asxb .asxb-logo-oscuro { display: block; }
