/*
 * Profile header layout.
 *
 * Allow profile information and badges to use their required space
 * without unnecessary sizing or overflow restrictions.
 */
.img-profile-data {
    min-width: 0;
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
    box-sizing: border-box;
}

/*
 * Profile title containing the company badge.
 *
 * Use flexbox to control the visual order of the profile name,
 * verified icon and company badge.
 */
h1.profile:has(.company-badges-container) {
    display: flex !important;
    flex-wrap: wrap;
    align-items: center;
    gap: 0 6px;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    height: auto !important;
    max-height: none !important;
    line-height: 1.5;
    white-space: normal !important;
    overflow: visible !important;
    text-overflow: clip !important;
    box-sizing: border-box;
}

/* Profile name link always appears first. */
h1.profile > a.link {
    order: 1;
    flex: 0 1 auto;
    min-width: 0;
    max-width: 100%;
    overflow-wrap: anywhere;
}

/*
 * Verified icon appears immediately after the profile name.
 */
h1.profile > i.fa-check-circle {
    order: 2;
    flex: 0 0 auto;
    display: inline-block;
    vertical-align: middle;
}

/*
 * Hide the empty badge container left inside the profile-name link
 * when the browser repairs the nested anchor markup.
 */
h1.profile a.link .company-badges-container:empty {
    display: none !important;
}

/*
 * Company badge link appears after the verified icon.
 */
h1.profile > a:has(> img.company-badge-icon) {
    order: 3;
    display: inline-flex !important;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    width: auto;
    max-width: 100%;
    height: auto;
    line-height: 0;
    margin-left: 0;
    overflow: visible !important;
    visibility: visible !important;
    opacity: 1 !important;
}

/*
 * Subtitle containing company badges.
 * Preserve normal inline text flow.
 */
h2.profile:has(> .company-badges-container) {
    display: block !important;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    min-height: 24px;
    height: auto !important;
    max-height: none !important;
    line-height: 1.5;
    white-space: normal !important;
    overflow: visible !important;
    text-overflow: clip !important;
    overflow-wrap: anywhere;
    box-sizing: border-box;
}

/*
 * Company badge container.
 */
.company-badges-container {
    display: inline-flex !important;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-start;
    gap: 4px;
    width: auto;
    max-width: 100%;
    min-width: 0;
    height: auto !important;
    max-height: none !important;
    margin-left: 8px;
    vertical-align: middle;
    white-space: normal;
    overflow: visible !important;
    visibility: visible !important;
    opacity: 1 !important;
    position: relative;
    z-index: 10;
    box-sizing: border-box;
}

/* Badge links inside the badge container. */
.company-badges-container a {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: auto;
    max-width: 100%;
    height: auto;
    line-height: 0;
    overflow: visible !important;
    visibility: visible !important;
    opacity: 1 !important;
    box-sizing: border-box;
}

/*
 * Profile-header badge images.
 */
.company-badges-container img.company-badge-icon,
h1.profile > a > img.company-badge-icon {
    display: block !important;
    width: 24px !important;
    height: 24px !important;
    min-width: 24px;
    max-width: 24px !important;
    min-height: 24px;
    max-height: 24px !important;
    object-fit: contain;
    border-radius: 4px;
    vertical-align: middle;
    visibility: visible !important;
    opacity: 1 !important;
}

/*
 * Mobile profile-header layout.
 */
@media (max-width: 575.98px) {

    .img-profile-data {
        width: 100%;
        max-width: 100%;
        min-width: 0;
        height: auto !important;
        max-height: none !important;
        overflow: visible !important;
    }

    /*
     * Profile name, verified icon and company badge.
     */
    h1.profile:has(.company-badges-container) {
        display: flex !important;
        flex-wrap: wrap;
        align-items: center;
        column-gap: 5px;
        row-gap: 3px;
        width: 100%;
        max-width: 100%;
        min-width: 0;
        height: auto !important;
        max-height: none !important;
        line-height: 1.5;
        white-space: normal !important;
        overflow: visible !important;
        overflow-wrap: anywhere;
        box-sizing: border-box;
    }

    h1.profile > a.link {
        flex: 0 1 auto;
        min-width: 0;
        max-width: 100%;
    }

    h1.profile > i.fa-check-circle {
        flex: 0 0 auto;
    }

    h1.profile > a:has(> img.company-badge-icon) {
        flex: 0 0 auto;
        margin: 0;
    }

    /*
     * Subtitle.
     */
    h2.profile:has(> .company-badges-container) {
        display: block !important;
        width: 100%;
        max-width: 100%;
        min-width: 0;
        min-height: 24px;
        height: auto !important;
        max-height: none !important;
        padding-bottom: 2px;
        line-height: 1.5;
        white-space: normal !important;
        overflow: visible !important;
        overflow-wrap: anywhere;
        text-overflow: clip !important;
        box-sizing: border-box;
    }

    /*
     * Company badges.
     */
    .company-badges-container {
        display: inline-flex !important;
        flex-wrap: wrap;
        align-items: center;
        justify-content: flex-start;
        gap: 3px;
        width: auto;
        max-width: 100%;
        min-width: 0;
        height: auto !important;
        max-height: none !important;
        margin-left: 5px;
        vertical-align: middle;
        overflow: visible !important;
        box-sizing: border-box;
    }

    .company-badges-container a {
        display: inline-flex !important;
        flex: 0 0 auto;
        align-items: center;
        justify-content: center;
        width: auto;
        max-width: 100%;
        height: auto;
        overflow: visible !important;
    }

    /*
     * Smaller badge icons on mobile.
     */
    .company-badges-container img.company-badge-icon,
    h1.profile > a > img.company-badge-icon {
        display: block !important;
        width: 22px !important;
        height: 22px !important;
        min-width: 22px;
        max-width: 22px !important;
        min-height: 22px;
        max-height: 22px !important;
        object-fit: contain;
    }
}

/* Management pages */
.company-badge-placeholder {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 2px dashed var(--bs-border-color);
    border-radius: 4px;
    color: var(--bs-secondary-color);
}

.company-badge-preview {
    border: 1px solid var(--bs-border-color);
}

.company-badge-item {
    transition: box-shadow .2s ease, opacity .2s ease;
}

.company-badge-item:hover {
    box-shadow: 0 2px 5px rgba(0, 0, 0, .1);
}

.company-badge-item.is-dragging {
    opacity: .5;
}

.company-badge-drag-handle {
    cursor: grab;
    color: var(--bs-secondary-color);
    padding: 5px;
}

.company-badge-drag-handle:hover {
    color: var(--bs-primary);
}
