/**
 * Workspaces switcher (top bar): dashboards + full-page tools, and Manage.
 */

.ws-host {
    position: relative;
    display: inline-flex;
    flex-shrink: 0;
    margin-left: var(--space-xs);
}

.ws-btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    height: 34px;
    padding: 0 var(--space-sm);
    border-radius: var(--radius-md);
    border: 1px solid rgba(var(--ink-rgb), 0.14);
    background: rgba(var(--ink-rgb), 0.06);
    color: var(--text-body);
    font-family: inherit;
    font-size: var(--font-size-sm);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s var(--ease);
}

.ws-btn:hover,
.ws-btn.is-open {
    background: rgba(var(--primary-rgb), 0.18);
    border-color: rgba(var(--primary-rgb), 0.4);
    color: var(--text-strong);
}

.ws-btn:focus-visible {
    outline: 2px solid var(--focus-ring);
    outline-offset: 2px;
}

.ws-btn svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.ws-btn-caption {
    color: var(--text-muted);
    font-weight: 500;
}

.ws-btn-current {
    max-width: 220px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ws-btn-current[hidden] {
    display: none;
}

.ws-popup {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    z-index: var(--z-overlay);
    width: 300px;
    max-height: 70dvh;
    display: flex;
    flex-direction: column;
    border-radius: var(--radius-lg);
    border: 1px solid rgba(var(--ink-rgb), 0.14);
    background: var(--bg-surface);
    box-shadow: var(--shadow-panel);
    overflow: hidden;
}

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

.ws-popup-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-xs);
    padding: 10px var(--space-sm);
    border-bottom: 1px solid var(--border);
}

.ws-popup-title {
    font-size: var(--font-size-xs);
    font-weight: 700;
    letter-spacing: 0.4px;
    text-transform: uppercase;
    color: var(--text-muted);
}

.ws-manage-toggle {
    border: 1px solid rgba(var(--ink-rgb), 0.14);
    background: rgba(var(--ink-rgb), 0.06);
    color: var(--text-body);
    font-family: inherit;
    font-size: var(--font-size-xs);
    font-weight: 600;
    padding: 4px 10px;
    border-radius: var(--radius-md);
    cursor: pointer;
}

.ws-manage-toggle[hidden] {
    display: none;
}

.ws-manage-toggle:hover {
    background: rgba(var(--primary-rgb), 0.18);
    border-color: rgba(var(--primary-rgb), 0.4);
    color: var(--text-strong);
}

.ws-popup-body {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: var(--space-xs);
    overflow-y: auto;
}

.ws-section {
    font-size: var(--font-size-xs);
    font-weight: 700;
    letter-spacing: 0.4px;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: var(--space-xs) 6px 2px;
}

.ws-section:first-child {
    padding-top: 2px;
}

.ws-empty {
    margin: 4px 6px;
    font-size: var(--font-size-xs);
    line-height: 1.5;
    color: var(--text-muted);
}

.ws-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px var(--space-sm);
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    background: rgba(var(--ink-rgb), 0.04);
    color: var(--text-body);
    font-family: inherit;
    font-size: var(--font-size-sm);
    font-weight: 600;
    text-align: left;
    cursor: pointer;
    transition: all 0.15s var(--ease);
}

.ws-item svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    opacity: 0.85;
}

.ws-item-label {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ws-item:hover {
    background: rgba(var(--primary-rgb), 0.18);
    color: var(--text-strong);
}

.ws-item.is-active {
    border-color: rgba(var(--primary-rgb), 0.55);
    background: rgba(var(--primary-rgb), 0.22);
    color: var(--text-strong);
}

.ws-item:focus-visible,
.ws-manage-toggle:focus-visible,
.ws-manage-star:focus-visible,
.ws-manage-name:focus-visible,
.ws-manage-action:focus-visible {
    outline: 2px solid var(--focus-ring);
    outline-offset: 2px;
}

/* LITE plan: listed but locked (the opener shows the upgrade wall). */
.ws-item.is-locked::after {
    content: '';
    width: 12px;
    height: 12px;
    flex-shrink: 0;
    opacity: 0.65;
    background: currentColor;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Crect x='3' y='11' width='18' height='11' rx='2'/%3E%3Cpath d='M7 11V7a5 5 0 0 1 10 0v4'/%3E%3C/svg%3E") center / contain no-repeat;
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Crect x='3' y='11' width='18' height='11' rx='2'/%3E%3Cpath d='M7 11V7a5 5 0 0 1 10 0v4'/%3E%3C/svg%3E") center / contain no-repeat;
}

/* --- Manage mode --- */

.ws-manage-row {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
}

.ws-manage-star,
.ws-manage-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    flex-shrink: 0;
    border: none;
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.15s var(--ease);
}

.ws-manage-star svg,
.ws-manage-action svg {
    width: 16px;
    height: 16px;
}

.ws-manage-star:hover {
    color: var(--color-warning);
}

.ws-manage-star.is-favorite {
    color: var(--color-warning);
}

.ws-manage-name {
    flex: 1;
    min-width: 0;
    padding: 9px 10px;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-body);
    font-family: inherit;
    font-size: var(--font-size-sm);
    font-weight: 600;
    text-align: left;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ws-manage-name:hover {
    background: rgba(var(--ink-rgb), 0.06);
    color: var(--text-strong);
}

.ws-manage-name.is-active {
    border-color: rgba(var(--primary-rgb), 0.5);
    color: var(--text-strong);
}

.ws-manage-actions {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
}

.ws-manage-action:hover {
    background: rgba(var(--primary-rgb), 0.18);
    color: var(--text-strong);
}

.ws-manage-delete:hover {
    background: rgba(var(--error-rgb), 0.14);
    color: var(--color-error);
}

/* --- Phone: compact button, popup spans the screen under the top bar --- */

@media (max-width: 768px), (orientation: landscape) and (max-height: 500px) {
    /* The org name truncates first; the switcher keeps its label readable. */
    .ws-host {
        margin-left: 0;
    }

    .ws-btn {
        height: var(--control-height);
    }

    .ws-btn:has(.ws-btn-current:not([hidden])) .ws-btn-caption {
        display: none;
    }

    .ws-btn-current {
        max-width: 110px;
    }

    .ws-popup {
        position: fixed;
        top: calc(52px + env(safe-area-inset-top, 0px));
        left: var(--space-xs);
        right: var(--space-xs);
        width: auto;
    }

    .ws-item,
    .ws-manage-name {
        min-height: var(--control-height);
    }
}
