/*
 * App switcher of the ERP applications.
 *
 * The only host is the django admin, so the panel takes its colours from the admin theme variables: it then
 * follows the light theme, the dark theme and the `auto` setting of the theme toggle without a rule of its
 * own. The button sits in `#header`, which keeps its colours in the two themes.
 *
 * Every rule is namespaced, and the panel is absolutely positioned against the button, so the host only has
 * to give the switcher a place in its own flow.
 */

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

.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.14);
    color: var(--header-link-color, #ffffff);
    cursor: pointer;
    transition: background-color 0.15s ease-in-out;
}

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

.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 var(--hairline-color, #e8e8e8);
    border-radius: 0.5rem;
    background-color: var(--body-bg, #ffffff);
    box-shadow: 0 0.5rem 1.5rem rgba(0, 0, 0, 0.28);
    color: var(--body-fg, #333333);
    font-family: var(--font-family-primary, inherit);
    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 var(--hairline-color, #e8e8e8);
    padding-top: 0.5rem;
}

.erp-app-switcher__section-label {
    margin: 0;
    padding: 0.5rem 1rem;
    color: var(--body-quiet-color, #666666);
    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: the admin styles `ul > li` directly — it
 * gives it a square marker and a padding — and a declaration on the item beats what the list passes down.
 * That marker is not only visible, it is laid out: safari gives it a line box of its own, which makes every
 * row 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.
 */
.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: var(--darkened-bg, #f8f8f8);
}

/*
 * The link takes its colour from the panel, and it must say so louder than the admin does: the switcher sits
 * in `#header`, where `#header a:link` paints every link with `--header-link-color` — white, over the 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.
 */
#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: var(--selected-row, #ffffcc);
}

.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: var(--darkened-bg, #f8f8f8);
    border: 1px solid var(--border-color, #cccccc);
    color: var(--body-quiet-color, #666666);
}

.erp-app-switcher__badge {
    background-color: var(--selected-bg, #e4e4e4);
    border: 1px solid var(--border-color, #cccccc);
    color: var(--body-medium-color, #444444);
    text-transform: none;
}
