/*
 * App switcher of the ERP applications.
 *
 * Every rule is namespaced, so that the switcher can be dropped in any host layout: an appstack sidebar
 * (`--sidebar`), an appstack navbar (`--topbar`) or the header of the django admin (`--admin`). The panel is
 * absolutely positioned against the button, so the host only has to give it a place in its own flow.
 */

.erp-app-switcher {
    position: relative;
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
}

.erp-app-switcher__button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    padding: 0;
    border: 0;
    border-radius: 0.5rem;
    background-color: rgba(255, 255, 255, 0.12);
    color: #ffffff;
    cursor: pointer;
    transition: background-color 0.15s ease-in-out;
}

.erp-app-switcher__button:hover {
    background-color: rgba(255, 255, 255, 0.22);
}

.erp-app-switcher__button:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 2px;
}

.erp-app-switcher__grid {
    width: 1.25rem;
    height: 1.25rem;
    fill: currentColor;
}

.erp-app-switcher__panel {
    position: absolute;
    z-index: 1050;
    top: calc(100% + 0.5rem);
    left: 0;
    width: 20rem;
    max-height: min(80vh, 42rem);
    overflow-y: auto;
    padding: 0.5rem 0;
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 0.5rem;
    background-color: #ffffff;
    box-shadow: 0 0.5rem 1.5rem rgba(0, 0, 0, 0.18);
    color: #212529;
    text-align: left;
}

.erp-app-switcher__panel[hidden] {
    display: none;
}

.erp-app-switcher__section + .erp-app-switcher__section {
    margin-top: 0.25rem;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    padding-top: 0.5rem;
}

.erp-app-switcher__section-label {
    margin: 0;
    padding: 0.5rem 1rem;
    color: #6c757d;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.erp-app-switcher__list {
    margin: 0;
    padding: 0;
    list-style: none;
}

/*
 * The item resets itself, it cannot rely on what the list holds: a host may style `ul > li` directly
 * — the django admin gives it a square marker and a padding — and a declaration on the item beats
 * anything the list would pass down. That marker is not only visible, it is laid out: safari gives it
 * a line box of its own, which made every row of the admin one line taller than it is drawn.
 *
 * It is a flex container for the same reason: a row then holds its link and nothing else, whatever a
 * host does to the items of a list.
 */
.erp-app-switcher__item {
    display: flex;
    margin: 0;
    padding: 0;
    list-style: none;
}

.erp-app-switcher__link {
    display: flex;
    flex: 1 1 auto;
    min-width: 0;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 1rem;
    color: inherit;
    font-size: 0.9375rem;
    font-weight: 500;
    line-height: 1.25;
    text-decoration: none;
}

.erp-app-switcher__link:hover {
    background-color: rgba(0, 0, 0, 0.04);
    color: inherit;
    text-decoration: none;
}

/*
 * The link takes its colour from the panel, and it must say so louder than the host does: the django admin
 * puts the switcher in `#header`, where `#header a:link` paints every link with `--header-link-color` —
 * white in the light theme, over the white panel — and `#header a:hover` underlines it. Those rules carry an
 * id, so an id and a link pseudo-class are what it takes to beat them. The panel stays the one place the
 * colour of a row is decided, whatever colours a host gives to the links it holds.
 */
#app-switcher-panel .erp-app-switcher__link:link,
#app-switcher-panel .erp-app-switcher__link:visited,
#app-switcher-panel .erp-app-switcher__link:hover,
#app-switcher-panel .erp-app-switcher__link:focus {
    color: inherit;
    text-decoration: none;
}

.erp-app-switcher__link--current {
    background-color: rgba(63, 128, 234, 0.08);
}

.erp-app-switcher__icon {
    flex: 0 0 auto;
    width: 2rem;
    height: 2rem;
    border-radius: 0.5rem;
}

.erp-app-switcher__name {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.erp-app-switcher__tag,
.erp-app-switcher__badge {
    flex: 0 0 auto;
    border-radius: 0.25rem;
    padding: 0.125rem 0.375rem;
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.erp-app-switcher__tag {
    background-color: rgba(0, 0, 0, 0.06);
    color: #6c757d;
}

.erp-app-switcher__badge {
    background-color: rgba(63, 128, 234, 0.14);
    color: #3f80ea;
    text-transform: none;
}

/* In an appstack navbar the button sits on a light background. */
.erp-app-switcher--topbar {
    margin: 0 1rem;
}

.erp-app-switcher--topbar .erp-app-switcher__button {
    background-color: rgba(0, 0, 0, 0.06);
    color: #495057;
}

.erp-app-switcher--topbar .erp-app-switcher__button:hover {
    background-color: rgba(0, 0, 0, 0.12);
}

/* In the header of the django admin the switcher borrows the colours of the admin theme. */
.erp-app-switcher--admin {
    margin-right: 1rem;
}

.erp-app-switcher--admin .erp-app-switcher__button {
    background-color: rgba(255, 255, 255, 0.14);
    color: var(--header-color, #ffffff);
}

.erp-app-switcher--admin .erp-app-switcher__button:hover {
    background-color: rgba(255, 255, 255, 0.26);
}

.erp-app-switcher--admin .erp-app-switcher__panel {
    border-color: var(--hairline-color, rgba(0, 0, 0, 0.08));
    background-color: var(--body-bg, #ffffff);
    color: var(--body-fg, #212529);
    font-family: var(--font-family-primary, inherit);
}

.erp-app-switcher--admin .erp-app-switcher__section + .erp-app-switcher__section {
    border-top-color: var(--hairline-color, rgba(0, 0, 0, 0.08));
}

.erp-app-switcher--admin .erp-app-switcher__section-label {
    color: var(--body-quiet-color, #6c757d);
}

.erp-app-switcher--admin .erp-app-switcher__link:hover {
    background-color: var(--darkened-bg, rgba(0, 0, 0, 0.04));
}

.erp-app-switcher--admin .erp-app-switcher__link--current {
    background-color: var(--selected-row, rgba(63, 128, 234, 0.08));
}

.erp-app-switcher--admin .erp-app-switcher__tag {
    background-color: var(--darkened-bg, rgba(0, 0, 0, 0.06));
    color: var(--body-quiet-color, #6c757d);
}

.erp-app-switcher--admin .erp-app-switcher__badge {
    background-color: var(--selected-bg, rgba(63, 128, 234, 0.14));
    color: var(--link-fg, #3f80ea);
}

/*
 * Places the host layouts give the switcher.
 */

/* Top of an appstack sidebar: the switcher and the name of the application share one row. */
.erp-sidebar-brand-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1.15rem 1.5rem;
}

.erp-sidebar-brand-row .sidebar-brand {
    padding: 0;
    text-align: left;
}

/* Name of the application in an appstack navbar, next to the switcher. */
.erp-navbar-brand {
    display: inline-flex;
    align-items: center;
    gap: 0.75rem;
    color: #495057;
    font-size: 1.0625rem;
    font-weight: 600;
    text-decoration: none;
}

.erp-navbar-brand:hover {
    color: #495057;
    text-decoration: none;
}

.erp-navbar-brand__icon {
    width: 2rem;
    height: 2rem;
    border-radius: 0.5rem;
}
