/* Sidebar workspace switcher — GoHighLevel-style right-side flyout. */

.workspace-switcher {
    position: relative;
    z-index: 30;
    box-sizing: border-box;
    width: 100%;
    min-width: 0;
}

.ws-switch-menu,
.ws-switch-menu *,
.ws-switch-backdrop {
    box-sizing: border-box;
}

.ws-switch-trigger {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    width: 100%;
    min-height: 52px;
    margin-top: 0.25rem;
    padding: 0.45rem 0.75rem 0.45rem 0.5rem;
    border: 1px solid var(--field-border);
    border-radius: var(--radius-control);
    background: var(--field-bg);
    color: var(--text-primary);
    font: inherit;
    font-family: var(--font-ui, "DM Sans", Arial, sans-serif);
    text-align: left;
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease;
}

.ws-switch-trigger:hover {
    border-color: var(--field-border-hover);
    background: var(--field-bg);
}

.workspace-switcher.is-open .ws-switch-trigger {
    border-color: var(--field-border-hover);
    background: var(--interactive-soft);
}

.ws-switch-trigger:focus-visible,
.ws-switch-item:focus-visible,
.ws-switch-link:focus-visible,
.ws-switch-search:focus-visible {
    outline: 2px solid var(--interactive-primary);
    outline-offset: 2px;
}

.ws-switch-avatar {
    position: relative;
    display: inline-grid;
    flex: 0 0 auto;
    place-items: center;
    overflow: hidden;
    width: 32px;
    height: 32px;
    border-radius: 10px;
    background: linear-gradient(135deg, #7655E9, #AA76EE);
    color: #FFFFFF;
    font-size: 0.85rem;
    font-weight: 700;
}

.ws-switch-avatar-initial {
    line-height: 1;
}

.ws-switch-avatar-img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: inherit;
}

.ws-switch-avatar.has-logo {
    background: var(--surface-elevated, var(--surface-page, #1a1a1f));
}

.ws-switch-avatar--lg {
    width: 64px;
    height: 64px;
    border-radius: 16px;
    font-size: 1.35rem;
}

.ws-switch-avatar--compact {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    font-size: 0.75rem;
}

.ws-switch-text {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    min-width: 0;
    line-height: 1.2;
}

.ws-switch-text small {
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.ws-switch-text strong,
.ws-switch-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ws-switch-text strong {
    font-size: 0.9rem;
    font-weight: 600;
}

.ws-switch-chevron {
    flex: 0 0 auto;
    color: var(--icon-muted);
    font-size: 0.75rem;
    transition: transform 0.18s ease;
}

.workspace-switcher.is-open .ws-switch-chevron {
    transform: rotate(-90deg);
}

/* Lightweight dismiss layer — not a modal dim. */
.ws-switch-backdrop {
    position: fixed;
    inset: 0;
    z-index: 80;
    background: transparent;
}

.ws-switch-backdrop[hidden] {
    display: none;
}

.ws-switch-menu {
    position: fixed;
    z-index: 90;
    display: flex;
    flex-direction: column;
    width: 400px;
    max-width: calc(100vw - 1.5rem);
    max-height: min(560px, calc(100vh - 24px));
    padding: 0;
    border: 1px solid var(--border-main);
    border-radius: 14px;
    background: var(--overlay-surface, var(--surface-page));
    color: var(--text-primary);
    box-shadow: var(--surface-shadow-overlay, 0 18px 48px rgba(0, 0, 0, 0.34));
    font-family: var(--font-ui, "DM Sans", Arial, sans-serif);
    overflow: hidden;
    animation: ws-flyout-in 0.16s ease-out;
}

.ws-switch-menu[hidden] {
    display: none;
}

.ws-switch-top {
    flex: 0 0 auto;
    padding: 0.75rem 0.75rem 0.55rem;
    border-bottom: 1px solid var(--border-soft);
}

.ws-switch-search {
    width: 100%;
    min-height: 40px;
    margin: 0;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--field-border);
    border-radius: 10px;
    background: var(--field-bg);
    color: var(--text-primary);
    font: inherit;
    font-size: 0.88rem;
}

.ws-switch-search::placeholder {
    color: var(--text-muted);
}

.ws-switch-search:hover {
    border-color: var(--field-border-hover);
}

.ws-switch-search:focus {
    outline: none;
    border-color: var(--interactive-primary);
    box-shadow: 0 0 0 3px var(--focus-ring, rgba(118, 85, 233, 0.18));
}

.ws-switch-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 0.45rem 0.45rem 0.35rem;
}

.ws-switch-heading {
    margin: 0.2rem 0.5rem 0.4rem;
    color: var(--text-muted);
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.ws-switch-list {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 2px;
    margin: 0;
}

.ws-switch-item,
.ws-switch-link {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    width: 100%;
    min-height: 48px;
    margin: 0;
    padding: 0.45rem 0.55rem;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--text-primary);
    font: inherit;
    font-size: 0.88rem;
    font-weight: 500;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}

.ws-switch-item[hidden] {
    display: none;
}

.ws-switch-item .ws-switch-avatar {
    width: 32px;
    height: 32px;
    border-radius: 9px;
    font-size: 0.8rem;
}

.ws-switch-meta {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    gap: 0.12rem;
    min-width: 0;
    line-height: 1.2;
}

.ws-switch-name {
    flex: 1 1 auto;
    min-width: 0;
    font-weight: 600;
}

.ws-switch-type {
    color: var(--text-muted);
    font-size: 0.72rem;
    font-weight: 500;
}

/* Inactive: neutral. Hover: restrained tint — not selected. */
.ws-switch-item:hover,
.ws-switch-link:hover {
    background: var(--menu-item-hover, rgba(128, 128, 140, 0.1));
    color: var(--text-primary);
}

.ws-switch-item.is-active {
    background: var(--interactive-soft);
    color: var(--text-primary);
    font-weight: 600;
}

.ws-switch-item.is-active:hover {
    background: var(--interactive-soft);
}

.ws-switch-check {
    flex: 0 0 auto;
    color: var(--interactive-primary, #7655e9);
    font-size: 0.82rem;
}

.ws-switch-empty {
    margin: 0.85rem 0.55rem 1rem;
    color: var(--text-muted);
    font-size: 0.86rem;
    text-align: center;
}

.ws-switch-empty[hidden] {
    display: none;
}

.ws-switch-footer {
    flex: 0 0 auto;
    display: grid;
    gap: 2px;
    padding: 0.4rem 0.45rem 0.5rem;
    border-top: 1px solid var(--border-soft);
    background: var(--overlay-surface, var(--surface-page));
}

.ws-switch-link {
    min-height: 42px;
    color: var(--text-sub-color);
    font-size: 0.86rem;
    font-weight: 500;
}

.ws-switch-link i {
    width: 32px;
    color: var(--brand-purple-soft, var(--interactive-primary));
    font-size: 0.82rem;
    text-align: center;
}

.ws-switch-link[aria-disabled="true"] {
    cursor: default;
    opacity: 0.75;
}

.ws-switch-link[aria-disabled="true"]:hover {
    background: transparent;
    color: var(--text-sub-color);
}

.ws-switch-link > span {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ws-switch-link-text {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.15rem;
}

.ws-switch-link-text > span {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ws-switch-soon {
    padding: 0.05rem 0.45rem;
    border-radius: 6px;
    background: var(--control-secondary);
    color: var(--control-secondary-text);
    font-size: 0.64rem;
    font-weight: 600;
    line-height: 1.4;
    white-space: nowrap;
}

@keyframes ws-flyout-in {
    from { opacity: 0; transform: translateX(-6px); }
    to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
    .ws-switch-menu {
        animation: none;
    }
}

/* Workspace rows are submit buttons; style.css paints every submit purple with !important. */
.workspace-switcher .ws-switch-list button.ws-switch-item[type="submit"],
.workspace-switcher .ws-switch-list button.ws-switch-item[type="submit"]:active {
    background: transparent !important;
    background-image: none !important;
    color: var(--text-primary) !important;
    border: 0 !important;
    border-radius: 10px;
    padding: 0.45rem 0.55rem;
    box-shadow: none;
    font-weight: 500;
    transform: none;
}

.workspace-switcher .ws-switch-list button.ws-switch-item[type="submit"]:hover,
.workspace-switcher .ws-switch-list button.ws-switch-item[type="submit"]:focus-visible {
    background: var(--menu-item-hover, rgba(128, 128, 140, 0.1)) !important;
    background-image: none !important;
    color: var(--text-primary) !important;
    box-shadow: none;
    transform: none;
}

.workspace-switcher .ws-switch-list button.ws-switch-item.is-active[type="submit"],
.workspace-switcher .ws-switch-list button.ws-switch-item.is-active[type="submit"]:hover,
.workspace-switcher .ws-switch-list button.ws-switch-item.is-active[type="submit"]:focus-visible,
.workspace-switcher .ws-switch-list button.ws-switch-item.is-active[type="button"],
.workspace-switcher .ws-switch-list button.ws-switch-item.is-active[type="button"]:hover {
    background: var(--interactive-soft) !important;
    background-image: none !important;
    color: var(--text-primary) !important;
}

html.light-theme .ws-switch-menu,
body.light-theme .ws-switch-menu {
    background: var(--overlay-surface, #FBFBFF);
    border-color: var(--overlay-surface-border, rgba(118, 85, 233, 0.16));
}

html.light-theme .ws-switch-item:hover,
html.light-theme .ws-switch-link:hover,
body.light-theme .ws-switch-item:hover,
body.light-theme .ws-switch-link:hover {
    background: rgba(48, 40, 72, 0.05);
}

html.light-theme .workspace-switcher .ws-switch-list button.ws-switch-item[type="submit"]:hover,
body.light-theme .workspace-switcher .ws-switch-list button.ws-switch-item[type="submit"]:hover {
    background: rgba(48, 40, 72, 0.05) !important;
}

/* Mobile: nearly full-height sheet instead of a tiny right float. */
@media (max-width: 768px) {
    .ws-switch-backdrop {
        background: rgba(12, 8, 24, 0.28);
    }

    html.light-theme .ws-switch-backdrop,
    body.light-theme .ws-switch-backdrop {
        background: rgba(24, 18, 40, 0.22);
    }

    .ws-switch-menu {
        left: 0 !important;
        right: 0 !important;
        top: auto !important;
        bottom: 0 !important;
        width: 100% !important;
        max-width: 100%;
        max-height: min(92dvh, 100%) !important;
        border-radius: 18px 18px 0 0;
        animation: ws-sheet-in 0.18s ease-out;
    }

    @keyframes ws-sheet-in {
        from { opacity: 0; transform: translateY(12px); }
        to { opacity: 1; transform: none; }
    }

    @media (prefers-reduced-motion: reduce) {
        .ws-switch-menu {
            animation: none;
        }
    }
}

/* Create workspace dialog — centered primary modal (not a corner popover). */
.ws-create-dialog {
    position: fixed;
    inset: 0;
    margin: auto;
    width: min(800px, calc(100vw - 2rem));
    max-width: calc(100vw - 2rem);
    height: fit-content;
    max-height: min(90dvh, 880px);
    padding: 0;
    border: 1px solid var(--overlay-surface-border, var(--border-main));
    border-radius: var(--radius-panel, 20px);
    background: var(--overlay-surface, var(--surface-page));
    color: var(--text-primary);
    box-shadow: var(--surface-shadow-overlay, 0 28px 64px rgba(8, 4, 18, 0.42));
    overflow: visible;
}

.ws-create-dialog::backdrop {
    background: rgba(12, 8, 24, 0.52);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
}

.ws-create-form {
    position: relative;
    display: flex;
    flex-direction: column;
    max-height: min(90dvh, 880px);
    min-height: 0;
}

.ws-create-close {
    position: absolute;
    top: 0.85rem;
    right: 0.85rem;
    z-index: 2;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    padding: 0;
    border: 0;
    border-radius: var(--radius-control, 12px);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
}

.ws-create-close:hover {
    background: var(--menu-item-hover, rgba(118, 85, 233, 0.11));
    color: var(--text-primary);
}

.ws-create-close:focus-visible {
    outline: 2px solid var(--interactive-primary);
    outline-offset: 2px;
}

.ws-create-header {
    flex: 0 0 auto;
    padding: 1.6rem 3.25rem 1rem 1.75rem;
    border-bottom: 1px solid var(--border-soft);
}

.ws-create-header h2 {
    margin: 0 0 0.45rem;
    font-family: var(--font-ui, "DM Sans", Arial, sans-serif);
    font-size: 1.4rem;
    font-weight: 650;
    line-height: 1.25;
    letter-spacing: -0.01em;
}

.ws-create-header p {
    margin: 0;
    max-width: 38rem;
    color: var(--text-secondary, var(--text-muted));
    font-size: 0.94rem;
    font-weight: 400;
    line-height: 1.5;
}

.ws-create-body {
    flex: 1 1 auto;
    min-height: 0;
    padding: 1.25rem 1.75rem 0.5rem;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.ws-create-fields {
    display: flex;
    flex-direction: column;
    gap: 1.15rem;
    /* Keep searchable-select lists from being clipped by a tight scroll box. */
    overflow: visible;
}

.ws-create-field {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    min-width: 0;
}

.ws-create-fields label,
.ws-create-address > label {
    margin: 0;
    color: var(--text-sub-color);
    font-size: 0.82rem;
    font-weight: 600;
    letter-spacing: 0.01em;
}

.ws-create-required,
.ws-create-optional {
    margin-left: 0.35rem;
    font-size: 0.72rem;
    font-weight: 500;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.ws-create-required {
    color: var(--interactive-primary, #7655e9);
}

.ws-create-optional {
    color: var(--text-muted);
}

.ws-create-pair {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 1rem 1.15rem;
}

.ws-create-dialog .ws-create-control,
.ws-create-dialog .ws-create-fields input,
.ws-create-dialog .ws-create-fields select,
.ws-create-dialog .searchable-select__input,
.ws-create-dialog .address-fields input,
.ws-create-dialog .address-fields select {
    box-sizing: border-box;
    width: 100%;
    min-height: 46px;
    padding: 0.65rem 0.85rem;
    border: 1px solid var(--field-border);
    border-radius: 12px;
    background: var(--field-bg);
    color: var(--text-primary);
    font: inherit;
    font-size: 0.95rem;
    line-height: 1.35;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.ws-create-dialog .ws-create-fields input:hover,
.ws-create-dialog .ws-create-fields select:hover,
.ws-create-dialog .searchable-select__input:hover,
.ws-create-dialog .address-fields input:hover,
.ws-create-dialog .address-fields select:hover {
    border-color: var(--field-border-hover);
}

.ws-create-dialog .ws-create-fields input:focus,
.ws-create-dialog .ws-create-fields select:focus,
.ws-create-dialog .searchable-select__input:focus,
.ws-create-dialog .address-fields input:focus,
.ws-create-dialog .address-fields select:focus {
    outline: none;
    border-color: var(--interactive-primary);
    box-shadow: 0 0 0 3px var(--focus-ring, rgba(118, 85, 233, 0.18));
}

.ws-create-address {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    padding-top: 0.35rem;
    border-top: 1px solid var(--border-soft);
}

.ws-create-dialog .address-fields {
    margin-top: 0.15rem;
    gap: 0.9rem;
}

.ws-create-dialog .searchable-select {
    width: 100%;
}

.ws-create-dialog .searchable-select__input {
    padding-right: 2.5rem;
}

.ws-create-dialog .searchable-select__list {
    z-index: 60;
    max-height: min(240px, 36vh);
}

.ws-create-actions {
    flex: 0 0 auto;
    display: flex;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 0.7rem;
    padding: 1rem 1.75rem 1.35rem;
    border-top: 1px solid var(--border-soft);
    background: var(--overlay-surface, var(--surface-page));
}

.ws-create-actions .btn-primary,
.ws-create-actions .btn-secondary {
    min-height: 44px;
    padding-inline: 1.15rem;
}

@media (max-width: 720px) {
    .ws-create-dialog {
        width: min(100vw - 1rem, 100%);
        max-width: calc(100vw - 1rem);
        max-height: min(94dvh, 100%);
        border-radius: 18px;
    }

    .ws-create-form {
        max-height: min(94dvh, 100%);
    }

    .ws-create-header {
        padding: 1.35rem 3rem 0.9rem 1.2rem;
    }

    .ws-create-header h2 {
        font-size: 1.25rem;
    }

    .ws-create-body {
        padding: 1rem 1.2rem 0.35rem;
    }

    .ws-create-pair {
        grid-template-columns: 1fr;
    }

    .ws-create-actions {
        padding: 0.9rem 1.2rem 1.15rem;
    }

    .ws-create-actions .btn-primary,
    .ws-create-actions .btn-secondary {
        flex: 1 1 auto;
        min-width: 8rem;
    }
}

@media (max-width: 480px) {
    .ws-create-dialog {
        width: 100vw;
        max-width: 100vw;
        max-height: 100dvh;
        border-radius: 0;
        border-left: 0;
        border-right: 0;
    }

    .ws-create-form {
        max-height: 100dvh;
    }

    .ws-create-actions {
        position: sticky;
        bottom: 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    .ws-create-dialog::backdrop {
        -webkit-backdrop-filter: none;
        backdrop-filter: none;
    }
}
