/**
 * Account switcher — the "Personal · Christopher" / "Business · Acme Coffee"
 * picker shared by /account and /partner. See app/switcher.js.
 *
 * Layers on styles.css and portal.css and only uses their palette variables.
 */

.account-switcher {
    position: relative;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.switcher-trigger {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    max-width: 100%;
    padding: 0.35rem 0.6rem 0.35rem 0.4rem;
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: 999px;
    font: inherit;
    color: var(--text-dark);
    cursor: pointer;
    text-align: left;
}

.switcher-trigger:hover { border-color: var(--text-light); }

.switcher-trigger:focus-visible,
.switcher-item:focus-visible,
.switcher-action:focus-visible,
.switcher-signout:focus-visible,
.switcher-cta:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

.switcher-trigger .switcher-identity { flex-direction: row; align-items: baseline; gap: 0.35rem; }
.switcher-trigger .switcher-kind::after { content: "·"; margin-left: 0.35rem; color: var(--text-light); }

.switcher-caret {
    width: 0;
    height: 0;
    margin-left: 0.1rem;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 5px solid var(--text-light);
    flex-shrink: 0;
}

.switcher-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.9rem;
    height: 1.9rem;
    flex-shrink: 0;
    border-radius: 50%;
    overflow: hidden;
    font-weight: 700;
    font-size: 0.85rem;
    color: #fff;
    background: var(--primary-color);
}

.switcher-avatar-business { border-radius: 0.45rem; background: #8B4513; }
.switcher-avatar-business img { width: 100%; height: 100%; object-fit: cover; background: #fff; }
.switcher-avatar-add { background: var(--background-alt); color: var(--primary-color); border: 1px dashed var(--primary-color); font-size: 1.1rem; }

.switcher-identity {
    display: flex;
    flex-direction: column;
    min-width: 0;
    line-height: 1.25;
}

.switcher-kind {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-light);
}

.switcher-name {
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 16rem;
}

.switcher-sub {
    font-size: 0.8rem;
    color: var(--text-light);
}

.switcher-menu {
    position: absolute;
    top: calc(100% + 0.4rem);
    right: 0;
    z-index: 50;
    width: 19rem;
    max-width: calc(100vw - 2rem);
    padding: 0.5rem;
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 10px 30px var(--shadow);
}

.switcher-heading {
    margin: 0.25rem 0.5rem 0.5rem;
    font-size: 0.78rem;
    color: var(--text-light);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.switcher-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.55rem 0.5rem;
    border-radius: 8px;
    color: var(--text-dark);
    text-decoration: none;
}

.switcher-item:hover { background: var(--background-alt); }
.switcher-item.is-current { background: var(--background-alt); }
.switcher-item .switcher-identity { flex: 1; }

.switcher-check { color: var(--primary-color); font-weight: 700; }

.switcher-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.4rem;
    margin: 0.25rem 0.5rem 0.5rem 3rem;
}

.switcher-action {
    display: block;
    padding: 0.4rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: 600;
    text-align: center;
    color: var(--primary-color);
    text-decoration: none;
}

.switcher-action:hover { background: var(--background-alt); }

.switcher-admin { font-size: 0.9rem; }

.switcher-pending { margin: 0.4rem 0.5rem; }

.switcher-signout {
    display: block;
    width: 100%;
    margin-top: 0.35rem;
    padding: 0.55rem 0.5rem;
    background: none;
    border: none;
    border-top: 1px solid var(--border);
    border-radius: 0 0 8px 8px;
    font: inherit;
    font-size: 0.9rem;
    text-align: left;
    color: var(--text-light);
    cursor: pointer;
}

.switcher-signout:hover { color: var(--text-dark); }

.switcher-cta {
    display: inline-block;
    padding: 0.4rem 0.8rem;
    border: 1px dashed var(--primary-color);
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--primary-color);
    text-decoration: none;
}

.switcher-cta:hover { background: var(--background); }

/*
 * On a phone the switcher can sit anywhere from the left edge to the right
 * edge of the header, so an absolutely positioned menu would hang off one
 * side or the other. It opens in the flow instead, full width, pushing the
 * page down.
 */
@media (max-width: 600px) {
    /* Whatever shares a header row with it (a Sign out button) wraps below. */
    :has(> .account-switcher) { flex-wrap: wrap; }
    .account-switcher { flex: 1 1 100%; min-width: 0; }
    .switcher-trigger { min-width: 0; }
    .switcher-menu { position: static; width: 100%; max-width: none; }
    .switcher-name { max-width: 60vw; }
}

@media (max-width: 480px) {
    .switcher-trigger .switcher-kind { display: none; }
}
