/**
 * Organization Switcher Styles
 * 
 * Styling for the organization switcher dropdown in the Wagtail admin.
 * Uses Wagtail's CSS custom properties for consistency.
 */

/* Switcher Container */
.org-switcher {
    position: relative;
    display: flex;
    align-items: center;
    margin: 0.75rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--w-color-border-furniture, rgba(255, 255, 255, 0.15));
}

/* Toggle Button */
.org-switcher__toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: transparent;
    border: 1px solid var(--w-color-border-furniture);
    border-radius: 0.375rem;
    cursor: pointer;
    color: var(--w-color-text-context);
    font-size: 0.875rem;
    transition: background-color 0.15s ease, border-color 0.15s ease;
    max-width: 250px;
    text-align: left;
}

.org-switcher__toggle:hover {
    background: var(--w-color-grey-50);
    border-color: var(--w-color-grey-200);
}

.org-switcher__toggle:focus {
    outline: 2px solid var(--w-color-focus);
    outline-offset: 2px;
}

.org-switcher__toggle[aria-expanded="true"] {
    background: var(--w-color-grey-50);
    border-color: var(--w-color-primary);
}

/* Current Organization Display */
.org-switcher__current {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.125rem;
    overflow: hidden;
    flex: 1;
    min-width: 0;
}

.org-switcher__org-name {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    width: 100%;
}

.org-switcher__org-name--placeholder {
    color: var(--w-color-text-meta);
    font-weight: 400;
}

.org-switcher__role {
    font-size: 0.6875rem;
    padding: 0.0625rem 0.375rem;
    background: var(--w-color-grey-100);
    border-radius: 0.25rem;
    color: var(--w-color-text-meta);
    white-space: nowrap;
}

.org-switcher__role--admin {
    background: var(--w-color-info-50);
    color: var(--w-color-info-100);
}

/* Dropdown Arrow */
.org-switcher__icon {
    width: 12px;
    height: 12px;
    flex-shrink: 0;
    transition: transform 0.15s ease;
}

.org-switcher__toggle[aria-expanded="true"] .org-switcher__icon {
    transform: rotate(180deg);
}

/* Dropdown Panel */
.org-switcher__dropdown {
    position: fixed;
    min-width: 280px;
    max-width: 350px;
    background: var(--w-color-surface-page);
    border: 1px solid var(--w-color-border-furniture);
    border-radius: 0.5rem;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
    z-index: 99999;
    overflow: visible;
}

.org-switcher__dropdown[hidden] {
    display: none;
}

/* Dropdown Header */
.org-switcher__header {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--w-color-border-furniture);
    background: var(--w-color-grey-50);
    border-radius: 0.5rem 0.5rem 0 0;
}

.org-switcher__header-text {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--w-color-text-meta);
}

/* Organization List */
.org-switcher__list {
    list-style: none;
    margin: 0;
    padding: 0.5rem 0;
    max-height: 300px;
    overflow-y: auto;
}

/* Organization Item */
.org-switcher__item {
    margin: 0;
    padding: 0;
}

.org-switcher__form {
    margin: 0;
}

.org-switcher__button {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0.625rem 1rem;
    background: transparent;
    border: none;
    cursor: pointer;
    text-align: left;
    color: inherit;
    transition: background-color 0.15s ease;
}

.org-switcher__button:hover {
    background: var(--w-color-grey-50);
}

.org-switcher__button:focus {
    outline: none;
    background: var(--w-color-grey-50);
}

.org-switcher__item--current .org-switcher__button {
    background: var(--w-color-grey-100);
    border-left: 3px solid var(--w-color-primary);
    padding-left: calc(1rem - 3px);
}

.org-switcher__item--current .org-switcher__button:hover {
    background: var(--w-color-grey-150);
}

/* Item Content */
.org-switcher__item-content {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
    min-width: 0;
    flex: 1;
}

.org-switcher__item-name {
    font-weight: 500;
    font-size: 0.875rem;
    color: var(--w-color-text-context);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.org-switcher__item-role {
    font-size: 0.75rem;
    color: var(--w-color-text-meta);
}

.org-switcher__item-role--admin {
    color: var(--w-color-info-100);
}

/* Current Indicator */
.org-switcher__check {
    width: 16px;
    height: 16px;
    color: var(--w-color-primary);
    flex-shrink: 0;
}

/* Divider between View All and organizations */
.org-switcher__divider {
    height: 1px;
    background: var(--w-color-border-furniture);
    margin: 0.5rem 1rem;
    padding: 0;
    list-style: none;
}

/* View All option styling */
.org-switcher__item--view-all .org-switcher__item-name {
    display: flex;
    align-items: center;
    font-weight: 600;
}

/* Sidebar placement - when injected into sidebar */
.sidebar .org-switcher,
.sidebar-main-menu .org-switcher {
    margin: 0;
    padding: 0.75rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    width: 100%;
}

.sidebar .org-switcher__toggle,
.sidebar-main-menu .org-switcher__toggle {
    width: 100%;
    justify-content: space-between;
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
    color: var(--w-color-text-label-menus-default, #fff);
    max-width: none;
    align-items: center;
}

.sidebar .org-switcher__current,
.sidebar-main-menu .org-switcher__current {
    flex: 1;
    min-width: 0;
}

.sidebar .org-switcher__toggle:hover,
.sidebar-main-menu .org-switcher__toggle:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.3);
}

.sidebar .org-switcher__role,
.sidebar-main-menu .org-switcher__role {
    background: rgba(255, 255, 255, 0.2);
    color: rgba(255, 255, 255, 0.9);
}

.sidebar .org-switcher__role--admin,
.sidebar-main-menu .org-switcher__role--admin {
    background: var(--w-color-secondary-100, #80d6c8);
    color: var(--w-color-primary, #2e1f5e);
}

/* Dropdown in sidebar - no special positioning needed with fixed positioning */

/* Slim header placement */
.w-slim-header__controls .org-switcher {
    margin: 0 1rem 0 0;
    padding: 0;
    border: none;
}

/* Footer placement */
.sidebar-footer .org-switcher {
    margin: 0;
    padding: 0.75rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    border-bottom: none;
}

/* Responsive adjustments for smaller screens */
@media (max-width: 768px) {
    .org-switcher__toggle {
        padding: 0.25rem 0.5rem;
    }

    .org-switcher__role {
        display: none;
    }

    .org-switcher__dropdown {
        right: -1rem;
        min-width: 260px;
    }
}

/* ============================================
 * Organization Switcher Search
 * ============================================ */

.org-switcher__search {
    padding: 0.5rem;
    border-bottom: 1px solid var(--w-color-border-furniture, #e0e0e0);
}

.org-switcher__search-input {
    width: 100%;
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--w-color-border-field-default, #ccc);
    border-radius: 4px;
    font-size: 0.875rem;
    background: var(--w-color-surface-page, #fff);
    color: var(--w-color-text-context, #333);
    outline: none;
    box-sizing: border-box;
}

.org-switcher__search-input:focus {
    border-color: var(--w-color-focus, #00b0b3);
    box-shadow: 0 0 0 2px var(--w-color-focus, #00b0b3);
}

.org-switcher__search-input::placeholder {
    color: var(--w-color-text-meta, #999);
}

/* ============================================
 * Organization Branding Logo Styles
 * ============================================
 * Styles for the dynamic organization logo that
 * replaces the default Wagtail branding logo.
 */

/* Organization logo in sidebar branding */
.org-branding-logo {
    max-width: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    display: block;
    margin: 0 auto;
}

/* When inside the sidebar branding link */
.sidebar-wagtail-branding .org-branding-logo,
.sidebar__branding .org-branding-logo {
    max-width: 160px;
    max-height: 80px;
}

/* Ensure the branding container can hold the org logo properly */
.sidebar-wagtail-branding[data-org-logo-active],
.sidebar__branding[data-org-logo-active],
.sidebar-wagtail-branding a[data-org-logo-active],
.sidebar__branding a[data-org-logo-active] {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Style the branding link when showing org logo */
.sidebar-wagtail-branding a:has(.org-branding-logo),
.sidebar__branding a:has(.org-branding-logo),
.sidebar-wagtail-branding__link:has(.org-branding-logo) {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 1rem;
}

/* Ensure logo is visible in both light and dark sidebar themes */
.sidebar .org-branding-logo {
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.1));
}

/* Collapsed sidebar adjustments */
.sidebar--collapsed .org-branding-logo {
    max-width: 32px;
    max-height: 32px;
    padding: 0;
}

/* Hide branding logo initially when org logo will be injected */
/* This prevents flash of default logo */
.sidebar-wagtail-branding[data-org-logo-pending] svg,
.sidebar-wagtail-branding[data-org-logo-pending] img:not(.org-branding-logo),
.sidebar__branding[data-org-logo-pending] svg,
.sidebar__branding[data-org-logo-pending] img:not(.org-branding-logo) {
    visibility: hidden;
}

/* Remove the CSS ::before fallback once JS has applied the real logo */
.org-logo-js-active .sidebar-wagtail-branding a::before,
.org-logo-js-active .sidebar-wagtail-branding__link::before {
    display: none !important;
}
